QuartzCore不动画?

时间:2013-08-05 21:59:43

标签: ios objective-c quartz-2d

我有一个View Controller,我在其中设置了一个UIImageView并希望在Xcode中使用QuartzCore为其设置动画 - 我将UIImage构建为一个旋转的图像视图。当我在它自己的项目中测试它时旋转很好但现在我将它拉入我当前的工作项目它添加了Image View但没有动画?不明白为什么?有什么想法吗?

我没有任何错误或警告,它与在单独项目中工作的代码相同?我还添加了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) 

1 个答案:

答案 0 :(得分: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.

}