给定:
1.logo
2.viewA contains:
a.username (uitextfield)
b.password (uitextfield)
c.login button
目标
1. shift a logo upward
2. when shifting is done, the view will be shown
第一种方法
使用 [UIView animateWithDuration: 选项:动画:完成:]
[UIView animateWithDuration:.4 delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
CGRect newFrame = self.logo.frame;
newFrame.origin.y = 29;
self.logo.frame = newFrame;
}
completion:^(BOOL finished) {
self.viewA.alpha = 1;
}
];
这个非常适合我
但是,我仍然在说服下面的第二种方法
第二种方法
首先将标志向上移动,我正在做
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
theAnimation.duration=1;
theAnimation.autoreverses=NO;
theAnimation.fromValue = [NSNumber numberWithFloat:0];
theAnimation.toValue = [NSNumber numberWithFloat:-60];
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
[self.flipgiveLogo1.layer addAnimation:theAnimation forKey:@"animateLayer"];
其次,我可以
self.viewA.alpha = 1;
显示视图。可悲的是,这些操作没有按顺序执行。
第一种方法不太可能使用块来保证按顺序执行的操作。我确实尝试过像下面这样使用 Grand Central Dispatch
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
// shifting logo goes here
dispatch_sync(dispatch_get_main_queue(), ^{
//displaying viewA goes here
});
});
这仍然困扰着我。请帮忙,如果你知道我在这里用 GCD 做错了什么。所有评论都在这里表示赞赏