0

UIView我需要在按下按钮或完成任务时给 a 一些拉伸和倾斜动画。

大多数应用到的动画UIView通常在它们被添加到或从 a 中删除时应用,UIView但是如何使用已经添加到视图的视图来实现这一点。

动画可以是任何东西,只要它能引起用户的注意(表明任务已完成)。

4

2 回答 2

1

简单的 UIView 动画;暂时扩大观点:

[UIView animateWithDuration:0.3 animations:^{
    CGRect frm = view.frame;
    frm.size.width += 20;
    frm.size.height += 20;
    frm.origin.x -= 10;
    frm.origin.y -= 10;
    view.frame = frm;
} completion:^{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect frm = view.frame;
        frm.size.width -= 20;
        frm.size.height -= 20;
        frm.origin.x += 10;
        frm.origin.y += 10;
        view.frame = frm;
    }];
}];
于 2012-08-13T06:08:46.037 回答
1

编辑 如何在单个动画中缩放和旋转视图

您可能需要使用核心动画并将两个动画添加到一个组中:

CABasicAnimation *stetchAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"];
stetchAnimation.toValue = [NSNumber numberWithDouble:(someView.frame.size.width+100)/someView.frame.size.width];

CABasicAnimation *skewAnimation = CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
stetchAnimation.toValue:[NSNumber numberWithInt:180];

//Add both animation at time when task is completed

CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = [NSArray arrayWithObjects:stetchAnimation,skewAnimation,nil];
animationGroup.removedOnCompletion = YES;
animationGroup.fillMode = kCAFillModeForwards;
animationGroup.duration = 0.7; // increase duration if needed

[someView.layer addAnimation:animationGroup forKey:@"animations"];
于 2012-08-13T05:38:29.473 回答