开发者

Page curl up - for landscape left and landscape right

I am trying to create a page turn application in xcode. The page turn works fine for landscape right but for landscape left, the page curl happens from the left. I added a container view and then the page curl on landscape left started happening from the bottom but not from right.

I found some suggestions here (http://stackoverflow.com/questions/4780488/i-want-to-use-animation-to-imageview-using-uianimationtransitioncurl-right-or-lef) and here (http://stackoverflow.com/questions/4780488/i-want-to-use-animation-to-imageview-using-uianimationtransitioncurl-right-or-lef)

but these both suggestions were with old style of page transition code and not with the block code. I tried to modify these with new block style code but it is not working for me.

I am attaching my code here:

- (void)viewDidLoad
{

    UIImage *img = [UIImage imageNamed:@"s1p1.png"];
    currentView.image = img;
    img = [UIImage imageNamed:@"s1p2.png"];
    swapView.image = img;

    UISwipeGestureRecognizer *nextPage;
    nextPage = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(turnPage)] autorelease];

    if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft) {
        [nextPage setDirection:UISwipeGestureRecognizerDirectionRight];
    }
    else {
    [nextPage setDirection:UISwipeGestureRecognizerDirectionLeft];
    }

    [self.view addGestureRecognizer:nextPage];

    [super viewDidLoad];
}

-(void) turnPage 
{

    if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft) 
    {
        NSLog(@"landscapeleft");
        mainView.transform = CGAffineTransformMakeRotation(M_PI);
        currentView.transform = CGAffineTransformMakeRotation(-M_PI); 
        swapView.transform = CGAffineTransformMakeRotation(-M_PI); 
        [UIView transitionWithView:mainView
                          duration:1
                           options:UIViewAnimationOptionTransitionCurlUp
                        animations:^{
                            currentView.hidden = YES;
                            swapView.hidden = NO;
                                    }
                        completion:^(BOOL finished){
                            UIImage    *temp = [currentView.image retain];
                            currentView.image = swapView.image;
                            swapView.image = temp;
                            [temp release];
                            currentView.hidden = NO;
                            swapView.hidden = YES;
                        }];

    }
    else
    {
        NSLog(@"landscaperight");
        [UIView transitionWithView:self.view
       开发者_StackOverflow社区                   duration:1
                           options:UIViewAnimationOptionTransitionCurlUp
                        animations:^{
                            currentView.hidden = YES;
                            swapView.hidden = NO;
                        }
                        completion:^(BOOL finished){
                            UIImage    *temp = [currentView.image retain];
                            currentView.image = swapView.image;
                            swapView.image = temp;
                            [temp release];
                            currentView.hidden = NO;
                            swapView.hidden = YES;
                        }];

    }


}

where I have two views: the self.view is the primary view from the window and then the mainView is my container view. currentView and SwapView are imageviews.

Any thoughts on this? Many thanks for reviewing this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜