UIImageView 与 CABasicAnimation 实现多层视图,带动画效果objec iOS
来源:互联网 发布:mac 网线转接头 编辑:程序博客网 时间:2024/05/18 15:53
- (void)viewDidLoad{ [super viewDidLoad]; int i; int n = 0; UIScrollView *newscrollview = [[UIScrollView alloc]init]; newscrollview.frame = CGRectMake(0, 0, 320, 400); [self.view addSubview:newscrollview]; newscrollview.backgroundColor = [UIColor brownColor]; //button.backgroundColor = [UIColor redColor]; //button.tag = 0; //关联事件。。butttest for(i = 0; i<20; i++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [newscrollview addSubview:button]; button.frame = CGRectMake(0, 1+n, 280, 110); button.backgroundColor = [UIColor redColor]; //与事件关联 调用buttest方法 [button addTarget:self action:@selector(butttest:) forControlEvents:UIControlEventTouchUpInside]; button.tag = i; //在视图里加载imageview视图 UIImageView *uiimageview = [[UIImageView alloc]init]; uiimageview.frame = CGRectMake(1, 1+n, 90, 110); UIImageView *uiimageview1 = [[UIImageView alloc]init]; UIImageView *uiimageview2 = [[UIImageView alloc]init]; uiimageview1.frame = CGRectMake(92, 1+n, 90, 110); uiimageview2.frame = CGRectMake(185, 1+n, 90, 110); [newscrollview addSubview:uiimageview1]; [newscrollview addSubview:uiimageview2]; uiimageview1.image = [UIImage imageNamed:@"three.png"]; uiimageview2.image = [UIImage imageNamed:@"four.png"]; [newscrollview addSubview:uiimageview]; //uiimageview.backgroundColor = [UIColor yellowColor]; uiimageview.image = [UIImage imageNamed:@"two.png"]; n = n + 113; } [newscrollview setContentSize:CGSizeMake(320, 2000)]; newscrollview.showsVerticalScrollIndicator = NO; // Do any additional setup after loading the view from its nib.}-(IBAction)butttest:(id)sender{ NSLog(@"next add a big button ...\n"); static int n=0 ; if(maximgbutton == nil) { maximgbutton = [UIButton buttonWithType:UIButtonTypeCustom]; maximgbutton.frame = CGRectMake(0, 0, 320, 400); //maximgbutton.backgroundColor = [UIColor redColor]; [self.view addSubview:maximgbutton]; } if( 2== ((UIButton*)sender).tag ) { [maximgbutton addTarget:self action:@selector(removebutton:) forControlEvents:UIControlEventTouchUpInside]; NSLog(@"successful"); if(imageviewts ==nil) { n++; CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; theAnimation.fromValue = [NSNumber numberWithFloat:0.09]; //移动的幅度 theAnimation.toValue = [NSNumber numberWithFloat:320]; //x,y轴缩小到0.1,Z 轴不变 //theAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(320, 400, 1.0)]; //持续时间 theAnimation.duration = 2; //重复次数 theAnimation.repeatCount = 1; theAnimation.removedOnCompletion = NO; theAnimation.autoreverses = YES; imageviewts = [[UIImageView alloc]init]; imageviewts = [imageviewts autorelease]; imageviewts.frame = CGRectMake(0, 0, 320, 400); imageviewts.image = [UIImage imageNamed:@"two.png"]; [self.view addSubview:imageviewts]; [imageviewts.layer addAnimation:theAnimation forKey:nil]; NSLog(@"nnnnnn%i",n); } else { imageviewts.frame = CGRectMake(0, 0, 320, 400); imageviewts.image = [UIImage imageNamed:@"two.png"]; [self.view addSubview:imageviewts]; } }}-(IBAction)removebutton:(id)sender{ NSLog(@"remove....button\n"); static int Calculator=0; Calculator ++; if(Calculator%2 !=0) { [imageviewts removeFromSuperview]; [maximgbutton removeFromSuperview]; maximgbutton =nil; imageviewts = nil ; } NSLog(@"Calculator%i",Calculator); }
-(IBAction)removebutton:(id)sender{ NSLog(@"remove....button\n"); static int Calculator=0; Calculator ++; if(Calculator%2 !=0) { CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; theAnimation.fromValue = [NSNumber numberWithFloat:0]; //移动的幅度 theAnimation.toValue = [NSNumber numberWithFloat:0]; //x,y轴缩小到0.1,Z 轴不变 //theAnimation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(320, 400, 1.0)]; //持续时间 theAnimation.duration = 2; //重复次数 theAnimation.repeatCount = 1; //theAnimation.delegate = self; //把imageviews这个视图加上theAnimation这个动画效果 [imageviewts.layer addAnimation:theAnimation forKey:nil]; //开始加载动画效果 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; [UIView setAnimationDelegate:self]; //view 大小 位置 imageviewts.frame = CGRectMake(-320, 0, 320, 400); //当动画停止的时候,调用hideAnimationStopped事件 [UIView setAnimationDidStopSelector:@selector(hideAnimationStopped)]; [UIView commitAnimations]; } NSLog(@"Calculator%i",Calculator); }
-(void)hideAnimationStopped{ NSLog(@"imageViewStop"); [imageviewts removeFromSuperview]; [maximgbutton removeFromSuperview]; maximgbutton =nil; imageviewts = nil ;}
- UIImageView 与 CABasicAnimation 实现多层视图,带动画效果objec iOS
- UIImageView实现动画效果
- iOS --用CABasicAnimation实现简单的动画效果
- iOS开发UIImageView动画效果
- UIImageView类实现动画效果
- 【iOS开发-动画】CABasicAnimation实现动画
- 用CABasicAnimation实现简单的动画效果
- iOS视图动画效果
- iOS UIImageview实现简单动画
- IOS动画效果与实现
- iOS动画(一):拍电影与CABasicAnimation
- iOS动画(一):拍电影与CABasicAnimation
- iOS动画(一):拍电影与CABasicAnimation
- iOS动画(一):拍电影与CABasicAnimation
- CABasicAnimation 热门动画效果
- CABasicAnimation 动画效果
- ios UIimageView 手势移动动画效果
- 实现 圆形加载view 动画效果(用CALayer,CABasicAnimation实现)
- objective-c UIImageView 操作
- objective-c NSArray 列出指定文件目录列表
- UIScrollView基本使用。为其它添加多个button ||-iOS objective-c
- objective-c 实现用户验证,登陆 Xcode iOS
- Oracle命令--查看表空间占用情况
- UIImageView 与 CABasicAnimation 实现多层视图,带动画效果objec iOS
- objective-c Http xml 文件解压 解析。NSXMLParser
- objective-c NSTimer 定时器
- POJ 1236 Network of Schools 强连通分量+缩点
- UISlider 滑动条基本属性
- objective-c 常用的一些控件。
- os x 一些常用命令
- Unix 下获得 root权限
- MAC OS X 系统终端的常用命令