2008-12-26 52 views

回答

16

我认为你正在寻找的唯一事情是:

的UIView的

+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache; 

UIViewAnimationTransitionFlipFromLeft, 
UIViewAnimationTransitionFlipFromRight, 

这些动画过渡只能在动画块中使用。转换在容器视图上设置,然后旧视图换出新视图,然后提交动画。

喜欢:

CGContextRef context = UIGraphicsGetCurrentContext(); 

[UIView beginAnimations:nil context:context]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:yourContainerView cache:YES]; 
[yourContainerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; 
[UIView commitAnimations]; 
+1

发现错字。应该是“exchangeSubviewAtIndex”而不是“exchangeSubviewsAtIndex”。谢谢。 – bentford 2009-04-28 22:40:49

0

把你的UIImageView到一个UIView,并使用此代码(从实用的应用项目,样品)

- (void)loadFlipsideViewController { 

    FlipsideViewController *viewController = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil]; 
    self.flipsideViewController = viewController; 
    [viewController release]; 

    // Set up the navigation bar 
    UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)]; 
    aNavigationBar.barStyle = UIBarStyleBlackOpaque; 
    self.flipsideNavigationBar = aNavigationBar; 
    [aNavigationBar release]; 

    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleView)]; 
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Test123"]; 
    navigationItem.rightBarButtonItem = buttonItem; 
    [flipsideNavigationBar pushNavigationItem:navigationItem animated:NO]; 
    [navigationItem release]; 
    [buttonItem release]; 
} 


- (IBAction)toggleView {  
    /* 
    This method is called when the info or Done button is pressed. 
    It flips the displayed view from the main view to the flipside view and vice-versa. 
    */ 
    if (flipsideViewController == nil) { 
     [self loadFlipsideViewController]; 
    } 

    UIView *mainView = mainViewController.view; 
    UIView *flipsideView = flipsideViewController.view; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES]; 

    if ([mainView superview] != nil) { 
     [flipsideViewController viewWillAppear:YES]; 
     [mainViewController viewWillDisappear:YES]; 
     [mainView removeFromSuperview]; 
     [infoButton removeFromSuperview]; 
     [self.view addSubview:flipsideView]; 
     [self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView]; 
     [mainViewController viewDidDisappear:YES]; 
     [flipsideViewController viewDidAppear:YES]; 

    } else { 
     [mainViewController viewWillAppear:YES]; 
     [flipsideViewController viewWillDisappear:YES]; 
     [flipsideView removeFromSuperview]; 
     [flipsideNavigationBar removeFromSuperview]; 
     [self.view addSubview:mainView]; 
     [self.view insertSubview:infoButton aboveSubview:mainViewController.view]; 
     [flipsideViewController viewDidDisappear:YES]; 
     [mainViewController viewDidAppear:YES]; 
    } 
    [UIView commitAnimations]; 
} 
0

MAINVIEW和flipToView是imageViews的目的和containerView是UIView的的对象。

下面给出两个示例代码卷曲的ImageView和翻转的ImageView从左至右

 
- (void)curlAction:(id)sender 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.75]; 

    [UIView setAnimationTransition:([mainView superview] ?       UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown)forView:containerView cache:YES]; 
    if ([flipToView superview]) 
    { 
     [flipToView removeFromSuperview]; 
     [containerView addSubview:mainView]; 
    } 
    else 
    { 
     [mainView removeFromSuperview]; 
     [containerView addSubview:flipToView]; 
    } 

    [UIView commitAnimations]; 
} 

,并从左至右这里的代码

 
- (void)flipAction:(id)sender 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.75]; 

    [UIView setAnimationTransition:([mainView superview] ? 
             UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) 
             forView:containerView cache:YES]; 
    if ([flipToView superview]) 
    { 
     [flipToView removeFromSuperview]; 
     [containerView addSubview:mainView]; 
    } 
    else 
    { 
     [mainView removeFromSuperview]; 
     [containerView addSubview:flipToView]; 
    } 

    [UIView commitAnimations]; 
} 

感谢带来的图像& Regards

0

另一个解决方案可在我的repo,但它不会涉及动画呢!它只操作图像方向来提供一些图像效果,即垂直/水平翻转和左右旋转90度。