我正在尝试用一些按钮和控制器将我的主视图从屏幕的右侧动画到屏幕中。问题是它不是动画,它只是直接转到完成状态。
这是我的代码:
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
options = [storyBoard instantiateViewControllerWithIdentifier:@"OptionsView"];
options.delegate = self;
[self.view addSubview:options.view];
options.view.center = CGPointMake(floor(total_width+options.view.frame.size.width/2)+10, floor(total_height/2));
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2));
}
completion:^(BOOL finished){
NSLog(@"Done!");
}]; 编辑
让事情变得更奇怪的是,如果我把这个动画放在另一个动画的完成块中,那么这个动画就可以工作了,但是新的动画就不行了。
UIButton* boton = (UIButton*) sender;
[UIView animateWithDuration:5.0
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
boton.alpha = 0.0;
//Jumps directly to 0, animation doesn't work
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2));
//It works now, but it doesn't take 5 seconds to start, it starts right away
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
}];发布于 2012-07-05 00:34:43
animateWithDuration:...调用之前的行将center直接分配给您要为其设置动画的相同值。要么将其删除,要么在其中指定初始center值。具有相同起始值和结束值的动画显然没有效果。
https://stackoverflow.com/questions/11330758
复制相似问题