Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

Flip View Iphone

please consider the code below, and tell me what I'm doing wrong.

I want to flip between two UIViews.

Somehow, when I flip away from the initial view, I just get the flipped view, without animation. When I flip back, the animation shows just fine.

The flips are triggered from buttons on the views themselves.

- (IBAction)showMoreInfo:(id)sender
{
    UIView *moreInfo = self.flipView;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationBeginsFromCurrentState:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

    UIView *parent = self.view.superview;
    [self.view removeFromSuperview];

    [parent addSubview:moreInfo];

    [UIView commitAnimations];

}



- (IBAction)showLessInfo:(id)sender
{
    UIView *lessInfo = self.view;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationBeginsFromCurrentState:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.flipView cache:YES];

    UIView *parent = self.flipView.superview;
    [self.flipView removeFromSuperview];

    [parent addSubview:lessInfo];

    [UIView commitAnimations];

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's probably because you aren't using a container view as the transition view. Refer to the documentation on setAnimationTransition:forView:cache:

If you want to change the appearance of a view during a transition—for example, flip from one view to another—then use a container view, an instance of UIView, as follows:

  1. Begin an animation block.
  2. Set the transition on the container view.
  3. Remove the subview from the container view.
  4. Add the new subview to the container view.
  5. Commit the animation block.

Try using self.view.superview in the animation transition view of the showMoreInfo:

The reason the showLessInfo: method works is you are using a container view.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...