humblePilgrim
humblePilgrim

Reputation: 1806

UISegmentedControl customization

I have a UISegmentedControl on one of my pages. I want an editbox to appear when a segment is clicked right below the clicked segment. I would like it to be animated (slide in or something)

Is this possible? What would be the best way to do this?

Damn.I forgot to mention all this action is going to occur within a cell and not a simple view.

Upvotes: 0

Views: 979

Answers (2)

Human-Behind
Human-Behind

Reputation: 98

Ok, so I will try to be more precise, I guess you are using Interface Builder ? So you have to "link" an action to you UISegmentedController, so in your class write this method :

-(IBAction) translateMyView
{
  //If the first segment is selected do translation of the cellView
  if(yourSegmentedController.selectedSegmentIndex == 0)
  {
    [UIView beginAnimation:nil context:nil];
    [UIView setAnimationDuration: 1.0];
    //This will translate the view to its position from its position -320 px
    CGAffineTransform trans = CGAffineTransformMakeTranslation(-320, 0);
    //Replace self.view with the view you want to translate.
    self.view.transform = trans;
    [UIView commitAnimations];
  }
  else if(yourSegementedController.selectedSegmentIndex ==1)
  {
    //Do same thing that above but with another view
  }
}

So this is the action that occure when you select an index in your segmentedController. What you have to do is linking this action to your UISegmentedController in Interface Builder.

Hope it will be helpfull ;-)

Upvotes: 0

Human-Behind
Human-Behind

Reputation: 98

You may try UIView animation. Firstly set your editbox (UITextView I guess ??) to x coordinate 320 (so it will not appear). Secondly when user hit the segmented control just translate your UITextView using UIView animation :

[UIView beginAnimation:nil context:nil];
[UIView setAnimationDuration: 1.0];
CGAffineTransform trans = CGAffineTransformMakeTranslation(-320, 0);
self.view.transform = trans;
[UIView commitAnimations];

Hope it will help you ;) .

Upvotes: 1

Related Questions