0

Ray 的 UIView 动画教程中,以下代码似乎完成了使野餐篮的顶部和底部打开并显示下方内容的工作:

- (void)viewDidAppear:(BOOL)animated
{

    CGRect basketTopFrame = self.basketTop.frame;
    basketTopFrame.origin.y = -basketTopFrame.size.height;

    CGRect basketBottomFrame = self.basketBottom.frame;
    basketBottomFrame.origin.y = self.view.bounds.size.height;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:1.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    self.basketTop.frame = basketTopFrame;
    self.basketBottom.frame = basketBottomFrame;

    [UIView commitAnimations];
}

从这个看起来像 basketFooFrame.origin.y 是篮子元素移动的正距离或负距离。这应该被理解为定义“您设置目标坐标并且示例将运行”的方法吗?

我的目标是制作比上面的技巧更详细的动画;UIView 具有特定的 x、y、高度、宽度和旋转,我希望通过缓动对其进行动画处理,使其水平和垂直居中,与视口一样高,可能减去一些边距,然后旋转回默认值方向(如果单击,则恢复到之前的状态)。

通过制作上述代码的更精细的副本,我会得到我想要的吗?

提前致谢,

4

1 回答 1

1

UIKit 动画主要是“设置它并忘记它”。但是,如果您在某个地方做某事,然后将其带回您开始的地方……那将需要两个动画块,因为您不能简单地说“从点 0,0 到点 0, 0 到 20,20 点”您必须说“转到 20,20 点,完成后转到 0,0 点”。例子:

#import <CoreGraphics/CoreGraphics.h>

#define degreesToRadians(x) (M_PI * x / 180.0)

// ...

[UIView animateWithDuration:.25 animations:^{
  CGAffineTransform t = CGAffineTransformIdentity;
  CGAffineTransformScale(t, 2.0, 2.0);
  CGAffineTransformRotate(t, degreesToRadians(45));

  myview.transform = t;

} completion:^(BOOL finished){
    NSLog(@"step 1 done");

    [UIView animateWithDuration:.25 animations:^{

      myview.transform = CGAffineTransformIdentity;

    } completion:^(BOOL finished) {

      NSLog(@"step 2 done");

    }];

}];
于 2013-10-04T13:31:09.970 回答