0

我有一个视图控制器,我在其中设置了一个 UIImageView 并想在 Xcode 中使用 QuartzCore 对其进行动画处理 - 我构建了 UIImage 以生活在一个旋转的图像视图中。当我在自己的项目中对其进行测试时,它旋转得很好,但是现在我将它拉入我当前的工作项目中,它添加了图像视图但没有动画?不知道为什么?有任何想法吗?

我没有任何错误或警告,它与在单独项目中工作的代码相同吗?我还添加了 QuartzCore 库和#imported

- (void)viewDidLoad {


    //Setup Image View
    UIImage *image = [UIImage imageNamed:@"record01.png"];
    UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
    [imgView setFrame: CGRectMake(0, 0, image.size.width, image.size.height)];
    [imgView setCenter:(CGPoint){160,160}];
    [self.view addSubview:imgView];

    //Animate Image View
    CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    fullRotation.fromValue = [NSNumber numberWithFloat:0];
    fullRotation.toValue = [NSNumber numberWithFloat:2 * M_PI];
    fullRotation.duration = 1.5;
    fullRotation.repeatCount = HUGE_VALF;
    [imgView.layer addAnimation:fullRotation forKey:@"fullRotation"];

    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

po [[UIApp keyWindow] recursiveDescription] 的控制台

   |    | <UIImageView: 0x984a9f0; frame = (-6.5 -6.5; 333 333); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x984a040>>
(lldb) po 0x984a040
(int) $2 = 159686720 <CALayer:0x984a040; position = CGPoint (160 160); bounds = CGRect (0 0; 333 333); delegate = <UIImageView: 0x984a9f0; frame = (-6.5 -6.5; 333 333); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x984a040>>; contents = <CGImage 0x9843560>; rasterizationScale = 2; contentsScale = 2>
(lldb) 
4

1 回答 1

0

CoreAnimation如果您可以在更高级别上获得的东西可以解决问题,我会置之不理:

- (void)spinOnce:(UIView *)view {
  CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI * 2);

  [UIView animateWithDuration:1.5
                   animations:^{
                     view.transform = rotate;
                   } completion:^(BOOL finished) {
                     view.transform = CGAffineTransformIdentity;
                     [self spinOnce:view];
                   }];
}

- (void)viewDidLoad {

  //Setup Image View
  UIImage *image = [UIImage imageNamed:@"record01.png"];
  UIImageView *imgView = [[UIImageView alloc] initWithImage:image];
  [imgView setFrame: (CGRect){{0,0},image.size}];
  [imgView setCenter:(CGPoint){160,160}];
  [self.view addSubview:imgView];

  //Animate Image View      
  [self spinOnce:imgView];

//  CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//  fullRotation.fromValue = [NSNumber numberWithFloat:0];
//  fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
//  fullRotation.duration = 1.5;
//  fullRotation.repeatCount = HUGE_VALF;
//  [imgView.layer addAnimation:fullRotation forKey:@"360"];
//  
//  [super viewDidLoad];
  // Do any additional setup after loading the view.

}
于 2013-08-05T22:22:46.797 回答