本文介绍了在iOS中,动画视图返回到原来的状态后手动调用SEGUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有两个视图控制器在一个SEGUE链接故事板。第一个视图控制器做它幻灯片从中间到屏幕顶部的UIImage的,然后显示一个UIButton的伟大工程的动画,全部。然而,当按钮被触动我执行SEGUE,presenting在一个模式的第二个视图控制器。但随着第二视图控制器向上滑动屏幕,我可以看到的UIImage返回,因为它是之前有人动画在屏幕的中间位置。

I have two View Controllers in the storyboard linked by a segue. The first View Controller does an animation where it slides an UIImage from the middle to the top of the screen and then shows a UIButton, all that works great. However, when the button gets touched I perform a segue, presenting the 2nd view controller on a modal. But as the 2nd View controller slides up the screen I can see that the UIImage returns to the middle of the screen as it was before it was animated.

这是它:

- (void)viewDidLoad{
    [super viewDidLoad];
    self.willAnimate=YES;
}

- (void)viewDidAppear:(BOOL)animated{
    if (self.willAnimate) [self animate];
}
- (void) animate{
    if (self.willAnimate){
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.8];
            //hide button first
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.1];
            self.myButton.alpha=0;
            [UIView commitAnimations];

        //move background
        CGRect imgRect = self.myImageView.frame;
        imgRect.origin.y-=200;
        self.myImageView.frame=backgroundRect;

        //restore button
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.5];
            [UIView setAnimationDelay:1.8];
            self.myButton.alpha=1;
            [UIView commitAnimations];
        [UIView commitAnimations];
        self.willAnimate=NO;
    }
}

- (IBAction)myButtonPressed {
    [self performSegueWithIdentifier:@"mySegue" sender:self ];
}

这是发生因为SEGUE是从故事板加载第一视图控制器?我怎么可以过渡来回视图控制器之间留下的形象,因为它是在动画后?

Is this happening because the segue is loading the 1st View Controller from the storyboard? How can I transition back and forth between the View Controllers leaving the image as it was after the animation?

推荐答案

这可能是由于自动布局。当你改变一帧上自动布局,这需要系统重新布局的意见,任何其他行动使帧恢复为约束定义的框架。因此,您应该关闭自动布局,或通过修改布局约束更改原点。当您使用自动布局,你不应该做的帧的任何设置,只修改限制。

This is probably due to auto layout. When you change a frame with auto layout on, any other action that requires the system to re-layout the views causes the frame to revert to the frame defined by the constraints. So, you should either turn off auto layout, or change the origin by modifying the layout constraints. When you use auto layout, you should never do any setting of frames, only modifying constraints.

这篇关于在iOS中,动画视图返回到原来的状态后手动调用SEGUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:32