- 论坛徽章:
- 0
|
窗口动画
首先,导入QuartzCore.framework,然后在头文件中加入:#import <QuartzCore/QuartzCore.h>
Ios代码- 1.- (void)viewDidLoad {
- 2. [super viewDidLoad];
- 3.
- 4. CGRect rect = CGRectMake(0.0f, 0.0f, 320.0f, 200.0f);
- 5. UIView *myView = [[UIView alloc] initWithFrame:rect];
- 6. myView.backgroundColor = [UIColor redColor];
- 7.
- 8. CABasicAnimation *animation1;
- 9. animation1 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
- 10. animation1.duration = 5;
- 11. animation1.repeatCount = 3;
- 12. animation1.autoreverses = YES;
- 13. animation1.fromValue = [NSNumber numberWithFloat:0];
- 14. animation1.toValue = [NSNumber numberWithFloat:-100];
- 15. [myView.layer addAnimation:animation1 forKey:@"animateLayer"];
- 16.
- 17. [self.view addSubview:myView];
- 18.
- 19. CABasicAnimation *animation2;
- 20. animation2 = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
- 21. animation2.duration = 1;
- 22. animation2.repeatCount = 10;
- 23. animation2.autoreverses = YES;
- 24. animation2.fromValue = [NSNumber numberWithFloat:0];
- 25. animation2.toValue = [NSNumber numberWithFloat:-60];
- 26. [self.view.layer addAnimation:animation2 forKey:@"animateLayer"];
- 27. [myView release];
- 28.}
复制代码 |
|