如何为UIview的某些部分制作动画

时间:2012-01-03 04:58:58

标签: iphone animation core-animation quartz-graphics

我有一个视图(默认来自UIViewController),上面的图像视图和顶部的工具栏。

       Toolbar
      ---------
     UIImageView
     -----------
       UIView

这是基本结构。我想动画UIView和UIImageView只是工具栏,目前当我使用代码时

CATransition *animation = [CATransition animation];

[animation setDelegate:self];
[animation setType:kCATransitionPush];

if ([directionScrolled isEqualToString:@"1"]) {
    [animation setSubtype:kCATransitionFromRight];
}
else if([directionScrolled isEqualToString:@"2"]){
    [animation setSubtype:kCATransitionFromLeft];
}

[animation setDuration:0.20];
[animation setTimingFunction:
 [CAMediaTimingFunction functionWithName:
  kCAMediaTimingFunctionDefault]];


[[self.view layer] addAnimation:animation forKey:kCATransition]; 

整个视图动画,(以及工具栏)。我想从动画中排除工具栏。

1 个答案:

答案 0 :(得分:0)

您可以像这样重新排列UI结构

  
      UIView ( this view is assigned to UIViewController )
       |
       |------Toolbar
       |------UIView ( lets take another UIView and name it as myView)
               |-------UIImageView
  

然后执行你的相同代码。 除,

   
 last line will be  [[self.myView layer] addAnimation:animation forKey:kCATransition];

确保