2008-12-26 62 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度。