简体   繁体   English

动画两种观点的问题

[英]Problems Animating Two Views

So what I want is when the user taps on the the sideNav button two seperate animations will occur. 所以我想要的是当用户点击sideNav按钮时会出现两个单独的动画。 The current view will slide out of the controller and a new view will slide in. I've set two different points of animation for the views but for some reason when the user taps on the sideNav button the views move as if they're connected. 当前视图将滑出控制器,新视图将滑入。我为视图设置了两个不同的动画点,但出于某种原因,当用户点击sideNav按钮时,视图会移动,就像它们已连接一样。 What am I doing wrong? 我究竟做错了什么?

- (IBAction)sideNav:(id)sender {

    if (draw1 == 0) {
        draw1 = 1;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [UIView setAnimationDelay:0.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

        navView.frame = CGRectMake(0, 0, 320, 568);
        newsView.frame = CGRectMake(320, 0, 320, 568);

        [UIView commitAnimations];
    } else {
        draw1 = 0;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [UIView setAnimationDelay:0.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

        navView.frame = CGRectMake(-320, 0, 320, 568);
        newsView.frame = CGRectMake(0, 0, 320, 568);

        [UIView commitAnimations];

    }

}

One step toward answering your question is to simplify your code. 回答问题的一步是简化代码。 First, unless it's used elsewhere as an integer, draw1 should be a BOOL , with values of YES and NO . 首先,除非它在其他地方用作整数, draw1应该是BOOL ,值为YESNO Second, no need for all that identical repeated code. 其次,不需要所有相同的重复代码。 It's much easier to understand something like: 理解类似的东西要容易得多:

- (IBAction)sideNav:(id)sender {

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.4];
    [UIView setAnimationDelay:0.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    navView.frame = draw1 ? CGRectMake(-320, 0, 320, 568) : CGRectMake(0, 0, 320, 568);
    newsView.frame = draw1 ? CGRectMake(0, 0, 320, 568) : CGRectMake(320, 0, 320, 568);

    [UIView commitAnimations];

    draw1 = !draw1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM