标签:
1.动画
1.1.转场动画
1.1.1渐变动画
1.1.2延时动画
1.1.3转场动画(由当前屏幕显示的视图过渡到另外的视图)
1.2.形变动画
1.3.帧动画
2.小球滚动
2.1设置全局属性ballButton;
2.2设置ballButton
2.2.1设置button对象 UIButton * ballButton = [UIButton buttonWithType:UIButtonTypeCustom];
2.2.2建立父子关系:[self.view addSubview:ballButton];
2.2.3设置正确的frame值ballButton.frame = CGRectMake(1,2,3,4);
2.2.4设置图片[ballButton setBackgroundImage:[UIImage imageName:@“Ball”] forState:UIControlStateNormal];
2.2.5事件[ballButton addTarget:self action:@selector()…];
2.3将ballButton赋值给_ballButton
2.4
2.4.1[UIView animateWithDuration:3 animations:^{
CGRect rect = self.ballButton.frame;
rect.origin.x += 10;
self.ballButton.frame = rect;
}];
2.4.2[UIView animateWithDuration:2 animations:^{
CGRect rect = self.ballButton.frame;
rect.origin.y += 300;
//进行整体Frame赋值
self.ballButton.frame = rect;
} completion:^(BOOL finished) {
//该block代码块,会在动画效果完全执行完成之后,进行调用
//self.ballButton.hidden = YES;
//设置视图的透明度变化范围 0.0 - 1.0 之间
self.ballButton.alpha = 0.5;
}];
2.4.3//渐变的方式改变alpha值
[UIView animateWithDuration:3 animations:^{
self.ballButton.alpha = 0.0;
}];
2.4.4//delay 要延时多长时间开始执行动画逻辑
//UIViewAnimationOptionAutoreverse 执行回路动画
//UIViewAnimationOptionRepeat 重复执行动画效果
//UIViewAnimationOptionRepeat| UIViewAnimationOptionAutoreverse 组合一起使用,钟摆效果
//UIViewAnimationOptionCurveEaseIn 由慢到快
//UIViewAnimationOptionCurveEaseOut 由快到慢
//UIViewAnimationOptionCurveLinear 匀速效果
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
CGRect rect = self.ballButton.frame;
rect.origin.y += 300;
//进行整体Frame赋值
self.ballButton.frame = rect;
} completion:^(BOOL finished) {
}];
3 view图片切换(转场动画)
3.1 View
3.1.1 MyView.h中对外创建对象接口 + (id)myViewWithFrame:(CGRect)frame;
3.1.2 MyView.m中创建Button和实现监听过程
全局变量:@property(nonatomic, weak)UIButton * redButton, * greenButton;
创建接口:return [[self alloc]initWithFrame:frame];
构造方法:if(self = [super initWithFrame:frame]){创建按钮} return self;
创建按钮:创建对象 UIButton * redButton = [UIButton buttonWithType:UIButtonTypeCustom];
建立父子关系 [self addSubview:redButton];
设立正确的frame值 redButton.frame = self.bounds;
设置背景颜色 [redButton setBackgroundColor:[UIColor redColor]];
设置背景图片 [redButton setBackgroundImage:[UIImage imageNamed:@"name"] forState:UIControlStateNormal];
添加监听事件[redButton addTarget:self action:@selector(buttonTouch:)...];
设置tag redButton.tag = 1;
赋给全局_redButton = redButton;
处理监听:NSLog(@"%ld",button.tag);
转场动画效果:
UIView * fromView = (button == _greenButton) ? _greenButton : self.redButton;
UIView * toView = (button == self.redButton) ? _greenButton : self.redButton;
[UIView transitionFromView:fromView toView:toView duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft|UIViewAnimationOptionShowHideTransitionViews completion:^(BOOL finished){
//fromView 转场动画完成之后,会把自己主动重父亲控件中移除
//UIViewAnimationOptionShowHideTransitionViews离场视图隐藏,不会从父控件中移除
}];
3.1.3 Controller文件中展示
创建对象 MyView * myView = [MyView myViewWithFrame:CGRect(x,y,w,h)];
建立父子关系[self.view addSubview:myView];
4 Tomcat(帧动画)
4.1 快速创建window
4.1.1创建window对象
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
4.1.2 显示window对象
[self.window makeKeyAndVisible];
4.1.3 设置背景颜色
self.window.backgroundColor = [UIColor whiteColor];
4.1.4 转交控制权
self.window.rootViewController = [[MyViewController alloc]init];
//程序加载jpg文件就要加上jpg后缀,png图片不需要加后缀名
//UIImageView 专门用来显示图片的,不能响应用户触摸事件
4.2 设置静态的背景UIImageView
创建对象
UIImageView * contentImageView = [[UIImageView alloc]init];
contentImageView.image = [UIImage imageNamed:@"angry_00.jpg"];
建立父子关系
[self.view addSubview:contentImageView];
设置正确的frame值
contentImageView.frame = self.view.bounds;
赋给全局
_contentImageView = contentImageView;
4.3 利用button方式捕捉事件
创建对象
UIButton * angryButton = [UIButton buttonWithType:UIButtonTypeCustom];
建立父子关系
[self.view addSubview:angryButton];
设置正确的frame值
angryButton.frame = CGRectMake(x,y,w,h);
添加事件
angryButton addTarget:self action:@selector(angryAnimation forControlEvents:UIControlEventTouchUpInside)
4.4 angryAnimation方法
- (void)angryAnimation{[self startAnimationWithName:@"angry" count:26];}
4.5 startAnimationWithName: count: 方法
防止动画之间相互干扰
if(self.contentImageView.isAnimation) return;
获得images
NSMutableArray * imagesArray = [NSMutableArray array];
for(int i = 0; i < count; i++){
NSString * name = [NSString stringWithFormat:@"%@_%02d.jpg",imageName];
NSString * path = [[NSBundle mainBundle] pathForResource:name ofType:nil];
UIImage * image = [UIImage imageWithContentOfFile:path];
[images addObject:image];
}
把所有的UIImage对象交给animationImages:
self.contentImageView.animationImages = images;
动画执行重复的次数:self.contentImageView.animationRepeatCount = 1;
动画执行持续的时间:self.contentImageView.animationDuration = images.count*0.1;
开始执行动画效果:[self.contentImageView startAnimating];
5 UIView中常用的方法
5.1 subviews获得当前视图管理的所有的子控件对象
NSLog(@"%ld",self.view.subviews.count);
5.2 把某一个视图放到最上层显示
[父视图 bringSubviewToFront:子视图中要放置到最上面的视图];
[self.view bringSubviewToFront:greenView];
5.3 把某一个视图放到最后面显示
[self.view sendSubviewToBack:redView];
5.4 在某视图的某个子视图下面放另一个子视图
[self.view insertSubview:blueView belowSubview:redView];
5.5 在选中的某个索引位置进行插入
[self.view insertSubview:yellowView atIndex:0];
5.6 把自己从父类控件中移除
如果把自己从父控件中移除,如果外部没有强指针再次指向自己,那么就会被销毁
[self.greenView removeFromSuperview];
//把自己内部管理的所有子控件删除掉
for(UIView * subView in self.redView.subviews)
{
[subView removeFromSuperview];
}
NSLog(@"redView subViews %ld", self.redView.subviews.count);
5.7
//当自己即将被添加到父亲视图上的时候就会被调用
//newSuperview即将被添加到的父亲是图对象
- (void)willMoveToSuperview:(UIView *)newSuperview
{
NSLog(@"frame %@",NSStringFromCGRect(newSuperview.frame));
NSLog(@"%@",NSStringFromSelector(_cmd));
}
//自己已经被安装到了父亲视图上的时候,会主动调用
- (void)didMoveToSuperview
{
NSLog(@"%@",NSStringFromSelector(_cmd));
}
标签:
原文地址:http://www.cnblogs.com/starainDou/p/5036200.html