我怎样才能使这个片段更漂亮/更好/更少的线条?

发布于 2024-12-23 21:18:25 字数 905 浏览 0 评论 0原文

我一直在尝试最小化应用程序中的所有功能,但无法真正找到如何使该功能更好,也许有人在这方面比我更好? :)

-(void)showRivBoxWithAnimtation:(BOOL)yesno {
    if(yesno) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.2];
        if ([self alpha] > 0) { 
            [self setAlpha:0.0];
            [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent!
        } else {
            [self setAlpha:1.0];
        }
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(clearRivBoxContent:finished:context:)];
        [UIView commitAnimations];
    } else {
        if ([self alpha] > 0) { 
            [self setAlpha:0.0];
            [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent!
        } else {
            [self setAlpha:1.0];
        }
    }
}

I've been trying to minimize all my functions in my app but can't really find how to make this function better, maybe someone is a lot better at this than me? :)

-(void)showRivBoxWithAnimtation:(BOOL)yesno {
    if(yesno) {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.2];
        if ([self alpha] > 0) { 
            [self setAlpha:0.0];
            [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent!
        } else {
            [self setAlpha:1.0];
        }
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(clearRivBoxContent:finished:context:)];
        [UIView commitAnimations];
    } else {
        if ([self alpha] > 0) { 
            [self setAlpha:0.0];
            [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent!
        } else {
            [self setAlpha:1.0];
        }
    }
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

预谋 2024-12-30 21:18:25

这就是我要做的:

-(void)showRivBoxWithAnimtation:(BOOL)yesno {
    [UIView animateWithDuration:yesno ? 0.2 : 0.0
                     animations:^{
        if ([self alpha] > 0) { 
            [self setAlpha:0.0];
            [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent!
        } else {
            [self setAlpha:1.0];
        }
        }
                    completion:^(BOOL finished){
        if (finished) {
            // Do the stuff from clearRivBoxContent:finished:context:
        }
    }];
}

This is what I would do:

-(void)showRivBoxWithAnimtation:(BOOL)yesno {
    [UIView animateWithDuration:yesno ? 0.2 : 0.0
                     animations:^{
        if ([self alpha] > 0) { 
            [self setAlpha:0.0];
            [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent!
        } else {
            [self setAlpha:1.0];
        }
        }
                    completion:^(BOOL finished){
        if (finished) {
            // Do the stuff from clearRivBoxContent:finished:context:
        }
    }];
}
素年丶 2024-12-30 21:18:25

除非操作顺序。阿尔法至关重要;这可能是可以制作的最小的了。

-(void)showRivBoxWithAnimtation:(BOOL)yesno {
  if ([self alpha] > 0) { 
    [self setAlpha:0.0];
    [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent!
  } else {
    [self setAlpha:1.0];
  }

  if(yesno) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(clearRivBoxContent:finished:context:)];
    [UIView commitAnimations];
  }
}

Unless the order of operations wrt. alpha is critical; this is probably the smallest it can be made.

-(void)showRivBoxWithAnimtation:(BOOL)yesno {
  if ([self alpha] > 0) { 
    [self setAlpha:0.0];
    [appDelegate.JSONparser setDelegate:self.delegate]; //Give back the JSONparser to the parent!
  } else {
    [self setAlpha:1.0];
  }

  if(yesno) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(clearRivBoxContent:finished:context:)];
    [UIView commitAnimations];
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文