Is it possible to spin a pickerview by shaking an iphone?

Discussion in 'iPhone' started by sakthivadivel.a, Oct 31, 2011.

  1. sakthivadivel.a, Oct 31, 2011
    Last edited: Nov 4, 2011

    sakthivadivel.a macrumors newbie

    Joined:
    Oct 31, 2011
    Location:
    chennai - -India
    #1
    I am developing an application for iPhone (iOS), as i am new to the apple technology having doubt. Is it possible to spin a pickerview control (or) move the selection indicator in pickerview automatically by shaking the iphone (i,e) i want to select values from pickerview either randomly or one after other by shaking the phone, if its so help in this regard.

    Thanks in Advance.

    sakthi.....:(:(
     
  2. thewitt macrumors 68020

    thewitt

    Joined:
    Sep 13, 2011
    #2
    Yes.... You can use movement of the phone to do anything you want programmatically.
     
  3. sakthivadivel.a, Nov 1, 2011
    Last edited: Nov 1, 2011

    sakthivadivel.a thread starter macrumors newbie

    Joined:
    Oct 31, 2011
    Location:
    chennai - -India
    #3
    could you please explain it?

    Could you please explain little elaborately technically, what method i have to use, how pickerview control receives the shake gesture.

    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
    if (event.subtype == UIEventSubtypeMotionShake)
    {

    self.view.backgroundColor = [UIColor redColor];


    }
    }

    using the above method i can easily change the iphone background color wih respect to the gesture, but my doubt is how pickerview scrolls with respect to the gesture.

    little elaboration highly appreciated.

    thanks
     
  4. psonice macrumors 6502a

    Joined:
    Jul 22, 2005
    #4
    Maybe read the pickerview docs, specifically the bits about animating it to a position? Or do you want us to read that for you and write your code for you? It's not difficult, detect the shake gesture, pick a random index, animate the pickerview.
     
  5. sakthivadivel.a thread starter macrumors newbie

    Joined:
    Oct 31, 2011
    Location:
    chennai - -India
    #5
    where to pick the random index?

    I don't know how to initiate it, from where to pick the random index. If possible simple code for that is very helpful for me. I think the above MOTIONBEGAN is the method which detects the gesture, i just want the code for inside this method how pickerview control receives the control or as you said index value for the shake gesture.

    Expecting the code.

    Thanks and regards
    sakthi
     
  6. lionqueen macrumors 6502

    Joined:
    Aug 30, 2009
    #6
    lol, "expecting the code"? This guy is too much. Who does he think he is, Steve Jobs?
     
  7. sakthivadivel.a thread starter macrumors newbie

    Joined:
    Oct 31, 2011
    Location:
    chennai - -India
    #7
    Just Guide it

    Else just guide it how and where to initiate it?
     
  8. nmork macrumors regular

    Joined:
    Jul 30, 2011
    Location:
    Under your bed.
    #10
    For what it's worth, I'm pretty sure he's not trying to be as rude as it's coming across. Sounds like English isn't his first language.
     
  9. sakthivadivel.a, Nov 4, 2011
    Last edited: Nov 4, 2011

    sakthivadivel.a thread starter macrumors newbie

    Joined:
    Oct 31, 2011
    Location:
    chennai - -India
    #11
    I tried it

    I tried but i am not getting the solution,


    -(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSString *string = [NSString stringWithFormat:mad:"%@",[list objectAtIndex:row]];
    labelField.text=string;
    pickerView.hidden = NO;
    }

    The above delegate method receives the control when we select any values in the pickerview by touch, but i didn't know how to write above mentioned delegate method functionalities into the below method,

    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
    if (event.subtype == UIEventSubtypeMotionShake)
    {
    //self.view.backgroundColor = [UIColor redColor];

    //self.view.frame
    self.view.backgroundColor = [UIColor redColor];
    //pickerView.hidden = TRUE;
    //[self.view removeFromSuperview:pickerView];


    /*if (! isSpinning)
    {
    [pickerView selectRow:(kRowMultiplier - 1) * [list count] -12 inComponent:0 animated:YES];
    }*/
    }
    }


    anyway i will try and get back with a solution soon.


    Thanks
     

Share This Page