0

我想讓我的照片庫像本書的頁面一樣動畫。 有沒有用,我既可以在左側或右側使用UIanimationtransitioncurl任何方法?我想使用UIanimationtransitioncurl右側或左側使用動畫進行圖像查看。可能嗎?

這是代碼,你建議我。我已經完成了viewdidload方法的分配。

self.title = @"TransitionsTitle"; 

// Create the container view which we will use for transition animation (centered horizontally). 
CGRect frame = CGRectMake(round((self.view.bounds.size.width - kImageWidth)/2.0), 
                kTopPlacement, kImageWidth, kImageHeight); 
self.containerView = [[[UIView alloc] initWithFrame:frame] autorelease]; 
[self.view addSubview:self.containerView]; 

// The container view can represent the images for accessibility. 
[self.containerView setIsAccessibilityElement:YES]; 
[self.containerView setAccessibilityLabel:NSLocalizedString(@"ImagesTitle", @"")]; 

// Create the initial image view. 
frame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight); 
self.mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease]; 
self.mainView.image = [UIImage imageNamed:@"scene1.jpg"]; 
[self.containerView addSubview:self.mainView]; 

// Create the alternate image view (to transition between). 
CGRect imageFrame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight); 
self.flipToView = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease]; 
self.flipToView.image = [UIImage imageNamed:@"scene2.jpg"]; 
CGAffineTransform rotate=CGAffineTransformMakeRotation(3.14/2); 
[containerView setTransform:rotate]; 
[self.view addSubview:containerView]; 
rotate=CGAffineTransformMakeRotation(-3.14/2); 
[mainView setTransform:rotate]; 
[self.containerView addSubview:mainView]; 
[self.mainView addSubview:flipToView]; 

//我已將它放在按鈕操作事件上。

- (IBAction)flipAction:(id)sender{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:4]; 
    [UIView setAnimationTransition:([self.mainView superview] ? 
             UIViewAnimationTransitionCurlDown : UIViewAnimationTransitionCurlDown) 
             forView:self.containerView cache:YES]; 
    if ([flipToView superview]) 
    { 
     [self.flipToView removeFromSuperview]; 
     [self.containerView addSubview:mainView]; 
    } 
    else 
    { 
     [self.mainView removeFromSuperview]; 
     [self.containerView addSubview:flipToView]; 
    } 
    [UIView commitAnimations]; 
} 
+0

嗨,你應該從我在viewDidLoad方法,而不是在行動本身第一個答案粘貼代碼(旋轉編碼)的第一部分。 – shannoga 2011-01-25 06:21:36

+0

您好,我仍然完成它沒有顯示你在談論的設定偏移你能幫助我,它是如何影響到動畫的結果呢? – NIKHIL 2011-01-25 06:56:11

回答

1

是的,你可以。這是我使用的代碼,

self.containerViewParent = [[[UIView alloc] initWithFrame:CGRectMake(what ever you want)] autorelease]; //Create a container parent for the container view. 

    self.containerView = [[[UIView alloc] initWithFrame:GRectMake(what ever you want)] autorelease]; //Create a container view for the view you wish to display. 

    CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2); 
    [containerViewParent setTransform:rotate]; //Rotate the containerViewParent. 

    [self.view addSubview:containerViewParent];//Add it to the main view. 

    rotate = CGAffineTransformMakeRotation(3.14/2); 
    [containerView setTransform:rotate];//Rotate the containerView. 

    [self.containerViewParent addSubview:containerView]; //Add it to the self.containerViewParent. 
    [self.containerView addSubview:viewToDisplay]; //Add the view you want to display. 

,然後應用過渡到父視圖,

[UIView beginAnimations:@"page transition" context:nil]; 
    [UIView setAnimationDuration:2.0]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.containerView cache:YES]; 
    [UIView commitAnimations]; 

,當你蜷縮上下將捲曲的左邊或右邊。

**請注意,您需要播放視圖的偏移量才能正確顯示, 但它對我很好。

相關問題