Chinaunix

标题: 窗口动画 [打印本页]

作者: feiyang10086    时间: 2011-12-12 21:23
标题: 窗口动画
窗口动画









首先,导入QuartzCore.framework,然后在头文件中加入:#import <QuartzCore/QuartzCore.h>





Ios代码
  1. 1.- (void)viewDidLoad {  
  2. 2.    [super viewDidLoad];  
  3. 3.      
  4. 4.    CGRect rect = CGRectMake(0.0f, 0.0f, 320.0f, 200.0f);  
  5. 5.    UIView *myView = [[UIView alloc] initWithFrame:rect];  
  6. 6.    myView.backgroundColor = [UIColor redColor];  
  7. 7.      
  8. 8.    CABasicAnimation *animation1;      
  9. 9.    animation1 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];  
  10. 10.    animation1.duration = 5;  
  11. 11.    animation1.repeatCount = 3;  
  12. 12.    animation1.autoreverses = YES;  
  13. 13.    animation1.fromValue = [NSNumber numberWithFloat:0];  
  14. 14.    animation1.toValue = [NSNumber numberWithFloat:-100];  
  15. 15.    [myView.layer addAnimation:animation1 forKey:@"animateLayer"];  
  16. 16.      
  17. 17.    [self.view addSubview:myView];  
  18. 18.      
  19. 19.    CABasicAnimation *animation2;      
  20. 20.    animation2 = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];  
  21. 21.    animation2.duration = 1;  
  22. 22.    animation2.repeatCount = 10;  
  23. 23.    animation2.autoreverses = YES;  
  24. 24.    animation2.fromValue = [NSNumber numberWithFloat:0];  
  25. 25.    animation2.toValue = [NSNumber numberWithFloat:-60];  
  26. 26.    [self.view.layer addAnimation:animation2 forKey:@"animateLayer"];  
  27. 27.    [myView release];  
  28. 28.}  
复制代码

作者: 梦境照进现实    时间: 2011-12-23 22:01
谢谢分享  希望于楼主多多交流




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2