#import "AppDelegate.h"
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[base release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
base = [[UIView alloc] initWithFrame:CGRectMake(60, 100, 200, 200)];
base.backgroundColor = [UIColor redColor];
[self.window addSubview:base];
/*
//UIView动画
//标记动画开始
[UIView beginAnimations:@"view101" context:@3];
//设置动画加减速方式
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//以秒为单位设置动画时长
[UIView setAnimationDuration:2.0];
//设置代理
[UIView setAnimationDelegate:self];
//设置动画结束后回掉的代理方法
// [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
//设置动画的重复次数
[UIView setAnimationRepeatCount:3];
//设置动画是否做一次反向执行
[UIView setAnimationRepeatAutoreverses:YES];
//视图的变化
base.alpha = 0;
//提交动画,标识动画块的结束
[UIView commitAnimations];
*/
//UIView blocks的动画
[UIView animateWithDuration:2
animations:^{
base.alpha = 0;
} completion:^(BOOL finished) {
NSLog(@"finished");
}];
UIView *view1 = [[UIView alloc] initWithFrame:base.bounds];
view1.backgroundColor = [UIColor blueColor];
[base addSubview:view1];
[view1 release];
UIView *view2 = [[UIView alloc] initWithFrame:base.bounds];
view2.backgroundColor = [UIColor purpleColor];
[base addSubview:view2];
[view2 release];
//UIImageView动画
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 200, 300)];
imgView.backgroundColor = [UIColor clearColor];
NSMutableArray *imgs = [NSMutableArray array];
for (int i = 0; i < 17; i++) {
NSString *name = [NSString stringWithFormat:@"campFire%02d.gif",i+1];
UIImage *img = [UIImage imageNamed:name];
if (img != nil) {
[imgs addObject:img];
}
}
//设置动画数组
imgView.animationImages = imgs;
//设置时长
[imgView setAnimationDuration:0.4];
//开始动画
[imgView startAnimating];
[self.window addSubview:imgView];
[imgView release];
return YES;
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
NSNumber *number = context;
NSLog(@"%@",number);
NSLog(@"%@",animationID);
if ([animationID isEqualToString:@"view101"]) {
NSLog(@"%@",animationID);
}
}
//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
// //设置动画的过度效果
// [UIView transitionWithView:base
// duration:1
// options:UIViewAnimationOptionTransitionCurlDown|UIViewAnimationOptionCurveEaseInOut
// animations:^{
// [base exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
// } completion:^(BOOL finished) {
//
// }];
//}
@end
UIView动画【渐入alpha、淡出、移动frame、缩放transform、旋转transform rotation】
最新推荐文章于 2023-04-18 18:01:47 发布