Animating UIView from right to left direction, iPhone
I am working on iPhone application. I am having a MemoryViewController page on which I have to display questions to the user for a particular time period. I have to reload same view with new question again and again. Here I have to apply view animation in the form of right to left move. and the new view will contain new question.
Have I to take 2 different views on the same parent view? or it can be impleme开发者_高级运维nted with same view.
Any code help, please.
Thanks.
I would make them in two different views, so you would end up with something like:
newQuestionView.frame=CGRectMake(360.0,0.0,newQuestionView.frame.size.width,newQuestionView.frame.size.height);
[UIView animateWithDuration:1
animations:^{
oldQuestion.frame=CGRectMake(-360.0, 0.0, oldQuestion.frame.size.width, oldQuestion.frame.size.height);
newQuestionView.frame=CGRectMake(0.0, 0.0, newQuestionView.frame.size.width, newQuestionView.frame.size.height);
}];
What will happen is:
- You first position the new question in the right side of the screen, so you can see it coming from the right. Then, inside the animation, you will put the old question in x=-360 and the new on in x=0, this way you will have the effect you want. In the
animateWithDuration:1
, you can change the 1 to whatever time you want the animation to last.
精彩评论