很抱歉,这是非常基本的,但我无法将AnimationOption从默认设置(EaseIn)设置为CurveLinear。这是我根据我在其他主题中阅读的内容尝试的内容:
-(void)animationShadow;
{
[UIView animateWithDuration:4
options:UIViewAnimationOptionCurveLinear
animations:^{
...
如果我取出选项位,一切正常。如果没有,它会崩溃。我确定我没有拨打正确的命令。
以下是整个块动画:
-(void)animationShadow;
{
[UIView animateWithDuration:4
options:UIViewAnimationOptionCurveLinear
animations:^{
//UIViewAnimationOptionCurveLinear
// animation 1
[pageShadowView setTransform:CGAffineTransformMakeScale (3, 1)];
[pageShadowView setFrame:CGRectMake(0-350, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
[UIView beginAnimations:@"pageCurlRightToLeftFinished" context:nil]; // Begin animation
//[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[pageShadowView setFrame:CGRectMake(0-280, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
[UIView commitAnimations];
} completion:^(BOOL finished){ ...
修改
好的,我现在更新了这个,但如果我做第二个动画,我仍然会崩溃。我收到警告:UIView可能无法响应+ animateWithDuration ...:
- (无效)animationShadow; {
[pageShadowView setTransform:CGAffineTransformMakeScale (3, 1)];
[pageShadowView setFrame:CGRectMake(0-350, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
[UIView animateWithDuration:kPageCurlSpeed/4
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
[pageShadowView setFrame:CGRectMake(0-280, 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
}
completion:^(BOOL finished){
[UIView animateWithDuration:kPageCurlSpeed
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
// animation 2
[pageShadowView setTransform:CGAffineTransformMakeScale (0.1, 1)];
[pageShadowView setFrame:CGRectMake((340-pageShadowView.frame.size.width), 0, CGRectGetWidth(pageShadowView.frame), CGRectGetHeight(pageShadowView.frame))];
}
]; // this is where I get the warning!!
}];
}
答案 0 :(得分:8)
编辑:动画初始化代码应放在动画块之外。该块指定视图在动画结束时应达到的最终状态。
[pageShadowView setTransform:CGAffineTransformMakeScale(3, 1)];
[pageShadowView setFrame:CGRectMake(-350, ...)];
[UIView animateWithDuration:4 delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
[pageShadowView setFrame:CGRectMake(-280, ...)];
}
completion:NULL];
如果要按顺序运行2个动画,则应将第2个动画放入completion
块。
[UIView animateWithDuration:4 delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{ /* animation 1 */ }
completion:^(BOOL finished) {
/* animation 2 */
}];
答案 1 :(得分:5)
如果您发现所选曲线被忽略,请检查您是否使用了正确的开关组。
有一个名为 UIViewAnimationCurveLinear (对于较旧的方法)和 UIViewAnimationOptionCurveLinear (对于块方法)并且很容易将它们混合起来。有相应的等效对,以方便,缓和等。
这引起了我的注意,所以我想我确保其他人可以很容易地看到这些信息。