ios - CGAffineTransformScale 和动画未按预期工作

标签 ios core-animation transformation

我正在创建一个故事书应用程序,它本质上是一系列短片动画。每个“翻页”只是一个页面缩小的短动画。对于page1,动画按预期工作,但是,对于page2,如果我在第一个动画仍在进行时调用 Action page2,它似乎会跳到正确的位置page1 就在那一刻,忽略它自己的持续时间、延迟等。

理想情况下,我希望动画 page2 在其自身缩小时播放,同样的方式,无论何时调用它,我可以在此代码中更改什么。

-(IBAction) page1
{
    pageImageNext.bounds = CGRectMake(-240, -370, 1200, 800);

    [UIImageView animateWithDuration:7.5 delay:2.0 options: UIViewAnimationOptionOverrideInheritedDuration |
                                                            UIViewAnimationOptionAllowUserInteraction animations:^{
        CGAffineTransform zoom = CGAffineTransformScale(CGAffineTransformIdentity, .4, .4); 
        self.pageImageNext.center = CGPointMake(240,160);
        self.pageImageNext.transform = zoom;

    } completion:^(BOOL finished) {}];
}

-(IBAction) page2
{
    pageImageNext.image = [UIImage imageNamed:@"page2.jpg"];
    pageImageNext.bounds = CGRectMake(-240, -370, 1200, 800);

    [UIImageView animateWithDuration:7.5 delay:6.0 options: UIViewAnimationOptionOverrideInheritedDuration |
                                                            UIViewAnimationOptionAllowUserInteraction | 
                                                            UIViewAnimationOptionBeginFromCurrentState animations: ^{
        CGAffineTransform zoom2 = CGAffineTransformScale(CGAffineTransformIdentity, .4, .4);    
        self.pageImageNext.center = CGPointMake(240,160);
        self.pageImageNext.transform = zoom2;

    } completion:^(BOOL finished) {}];
}

此外,行 pageImageNext.bounds = CGRectMake(-240, -370, 1200, 800); 似乎在 page2,因为它没有调整 UImageView 的大小,而是似乎从之前的转换中“继承”了它的当前大小。

谢谢!

最佳答案

我实际上还没有弄清楚上面出了什么问题,尽管我已经发现通过使用核心动画,通过在每个 IBAction 中使用此代码,我确实获得了正确的效果:

pageImageNext.image = [UIImage imageNamed:@"page1.jpg"];
pageImageNext.bounds = CGRectMake(-240, -470, 1200, 800);

CABasicAnimation *zoomOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
zoomOut.beginTime = CACurrentMediaTime()+4;
zoomOut.toValue = [NSNumber numberWithDouble:0.4];
zoomOut.duration = 8.0;
zoomOut.fillMode=kCAFillModeForwards;
zoomOut.removedOnCompletion=NO;
[pageImageNext.layer addAnimation:zoomOut forKey:@"zoomOut"];

关于ios - CGAffineTransformScale 和动画未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7458460/

相关文章:

objective-c - NSPopover 的 contentViewController 中的动画变化

scala - Spark : How to map an RDD when access to another RDD is required

r - R 中的 log10 转换

math - 平面中的变形点

iphone - 如何检查UIDatePicker中的日期是否被修改?

ios - Unity 脚本 armv7 错误

ios - iOS 中的断断续续的动画

objective-c - 如何将 iOS 元素组合在一起,以便可以将它们作为单个元素进行操作

iphone - 解析 JSON 并更改我的模型而不阻塞 UI

IOS Objective-C 选择器使用了错误的范围