views:

67

answers:

3

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.

+1  A: 

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 ;) .

Human-Behind
thnx...Im new to this stuff(1 month experience).I understand the logic but dont know where do the animation,especially since this is happening inside a cellview
Mithun Madhav
A: 

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 ;-)

Human-Behind
Seems im the one who needs to be preciseive a table view each cell of which contains a segmentedcontrol with a segment for each day of the week(7 segments in total).I want a text box to appear below the day,when its segment is pressed,in which the user can enter his data.now since there can be any number of cells in the table,(all with there own UISegmentedControls),the problem becomes complicated.Im ready to dump the animation part but the TextView has to appear,below the corresponding day.
Mithun Madhav
and by edit box I mean TextField not TextView
Mithun Madhav
Thnx for the effort you put in to help me
Mithun Madhav
A: 

Could you try to make a picture (image) of what you wanted to do , because I don't understand the part where you want to display a TextField.

Tell me if I'm write , you have a UITableView in which are some UICellView. In those UICellView you have a seven segmentedControll, ok so what do you want to do when a user press a segmentedControll ? A UITextView has to appear on screen, over the current UITableView ?

Human-Behind
thnxx human behind for your attention.Ive solved my problem and its now working the way i wanted it to.Its not animated,though.what i wanted was a UITextField to appear right below the selected segment,so that the user can enter the required data.Thnxx so much or your help.Its part of my work so cant paste screen shots.
Mithun Madhav
You're welcome. You can animate whatever View you want using my function. I suggest you to make a test project to train you using UIView animation if you have time ;-) .See you and good luck for your project.
Human-Behind