窗口动画

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

 

- (void)viewDidLoad {
	[super viewDidLoad];
	
	CGRect rect = CGRectMake(0.0f, 0.0f, 320.0f, 200.0f);
	UIView *myView = [[UIView alloc] initWithFrame:rect];
	myView.backgroundColor = [UIColor redColor];
	
	CABasicAnimation *animation1;    
	animation1 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
	animation1.duration = 5;
	animation1.repeatCount = 3;
	animation1.autoreverses = YES;
	animation1.fromValue = [NSNumber numberWithFloat:0];
	animation1.toValue = [NSNumber numberWithFloat:-100];
	[myView.layer addAnimation:animation1 forKey:@"animateLayer"];
	
	[self.view addSubview:myView];
	
	CABasicAnimation *animation2;    
	animation2 = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
	animation2.duration = 1;
	animation2.repeatCount = 10;
	animation2.autoreverses = YES;
	animation2.fromValue = [NSNumber numberWithFloat:0];
	animation2.toValue = [NSNumber numberWithFloat:-60];
	[self.view.layer addAnimation:animation2 forKey:@"animateLayer"];
	[myView release];
}

 

你可能感兴趣的:(ios,iPhone,窗口动画)