页面卷曲 - 适用于横向左和横向右

发布于 2024-11-25 23:33:12 字数 3169 浏览 1 评论 0原文

我正在尝试在 xcode 中创建一个翻页应用程序。翻页对于横向右侧效果很好,但对于横向左侧,翻页从左侧发生。我添加了一个容器视图,然后横向左侧的页面卷曲开始从底部发生,而不是从右侧发生。

我在这里找到了一些建议(http://stackoverflow.com/questions/4780488/i-want-to-use-animation-to-imageview-using-uianimationtransitioncurl-right-or-lef)和这里(http://stackoverflow.com/questions/4780488/i-want-to-use-animation-to-imageview-using-uianimationtransitioncurl-right-or-lef)

但这两个建议都是使用旧样式的页面转换代码和不是用块代码。我尝试用新的块样式代码修改这些,但它对我不起作用。

我在这里附加我的代码:

- (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
                          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;
                        }];

    }


}

我有两个视图:self.view 是窗口的主视图,然后 mainView 是我的容器视图。 currentView 和 SwapView 是图像视图。

对此有什么想法吗?非常感谢您对此进行评论。

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
                          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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文