UIImageView 与 CABasicAnimation 实现多层视图,带动画效果objec iOS
2013-05-31 17:13
302 查看
-(void)viewDidLoad { [superviewDidLoad]; inti; intn=0; UIScrollView*newscrollview=[[UIScrollViewalloc]init]; newscrollview.frame=CGRectMake(0,0,320,400); [self.viewaddSubview:newscrollview]; newscrollview.backgroundColor=[UIColorbrownColor]; //button.backgroundColor=[UIColorredColor]; //button.tag=0; //关联事件。。butttest for(i=0;i<20;i++) { UIButton*button=[UIButtonbuttonWithType:UIButtonTypeCustom]; [newscrollviewaddSubview:button]; button.frame=CGRectMake(0,1+n,280,110); button.backgroundColor=[UIColorredColor]; //与事件关联调用buttest方法 [buttonaddTarget:selfaction:@selector(butttest:)forControlEvents:UIControlEventTouchUpInside]; button.tag=i; //在视图里加载imageview视图 UIImageView*uiimageview=[[UIImageViewalloc]init]; uiimageview.frame=CGRectMake(1,1+n,90,110); UIImageView*uiimageview1=[[UIImageViewalloc]init]; UIImageView*uiimageview2=[[UIImageViewalloc]init]; uiimageview1.frame=CGRectMake(92,1+n,90,110); uiimageview2.frame=CGRectMake(185,1+n,90,110); [newscrollviewaddSubview:uiimageview1]; [newscrollviewaddSubview:uiimageview2]; uiimageview1.image=[UIImageimageNamed:@"three.png"]; uiimageview2.image=[UIImageimageNamed:@"four.png"]; [newscrollviewaddSubview:uiimageview]; //uiimageview.backgroundColor=[UIColoryellowColor]; uiimageview.image=[UIImageimageNamed:@"two.png"]; n=n+113; } [newscrollviewsetContentSize:CGSizeMake(320,2000)]; newscrollview.showsVerticalScrollIndicator=NO; //Doanyadditionalsetupafterloadingtheviewfromitsnib. } -(IBAction)butttest:(id)sender { NSLog(@"nextaddabigbutton...\n"); staticintn=0; if(maximgbutton==nil) { maximgbutton=[UIButtonbuttonWithType:UIButtonTypeCustom]; maximgbutton.frame=CGRectMake(0,0,320,400); //maximgbutton.backgroundColor=[UIColorredColor]; [self.viewaddSubview:maximgbutton]; } if(2==((UIButton*)sender).tag) { [maximgbuttonaddTarget:selfaction:@selector(removebutton:)forControlEvents:UIControlEventTouchUpInside]; NSLog(@"successful"); if(imageviewts==nil) { n++; CABasicAnimation*theAnimation; theAnimation=[CABasicAnimationanimationWithKeyPath:@"transform.translation.x"]; theAnimation.fromValue=[NSNumbernumberWithFloat:0.09]; //移动的幅度 theAnimation.toValue=[NSNumbernumberWithFloat:320]; //x,y轴缩小到0.1,Z轴不变 //theAnimation.toValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(320,400,1.0)]; //持续时间 theAnimation.duration=2; //重复次数 theAnimation.repeatCount=1; theAnimation.removedOnCompletion=NO; theAnimation.autoreverses=YES; imageviewts=[[UIImageViewalloc]init]; imageviewts=[imageviewtsautorelease]; imageviewts.frame=CGRectMake(0,0,320,400); imageviewts.image=[UIImageimageNamed:@"two.png"]; [self.viewaddSubview:imageviewts]; [imageviewts.layeraddAnimation:theAnimationforKey:nil]; NSLog(@"nnnnnn%i",n); } else { imageviewts.frame=CGRectMake(0,0,320,400); imageviewts.image=[UIImageimageNamed:@"two.png"]; [self.viewaddSubview:imageviewts]; } } } -(IBAction)removebutton:(id)sender { NSLog(@"remove....button\n"); staticintCalculator=0; Calculator++; if(Calculator%2!=0) { [imageviewtsremoveFromSuperview]; [maximgbuttonremoveFromSuperview]; maximgbutton=nil; imageviewts=nil; } NSLog(@"Calculator%i",Calculator); }
-(IBAction)removebutton:(id)sender { NSLog(@"remove....button\n"); staticintCalculator=0; Calculator++; if(Calculator%2!=0) { CABasicAnimation*theAnimation; theAnimation=[CABasicAnimationanimationWithKeyPath:@"transform.translation.x"]; theAnimation.fromValue=[NSNumbernumberWithFloat:0]; //移动的幅度 theAnimation.toValue=[NSNumbernumberWithFloat:0]; //x,y轴缩小到0.1,Z轴不变 //theAnimation.toValue=[NSValuevalueWithCATransform3D:CATransform3DMakeScale(320,400,1.0)]; //持续时间 theAnimation.duration=2; //重复次数 theAnimation.repeatCount=1; //theAnimation.delegate=self; //把imageviews这个视图加上theAnimation这个动画效果 [imageviewts.layeraddAnimation:theAnimationforKey:nil]; //开始加载动画效果 [UIViewbeginAnimations:nilcontext:nil]; [UIViewsetAnimationDuration:1]; [UIViewsetAnimationDelegate:self]; //view大小位置 imageviewts.frame=CGRectMake(-320,0,320,400); //当动画停止的时候,调用hideAnimationStopped事件 [UIViewsetAnimationDidStopSelector:@selector(hideAnimationStopped)]; [UIViewcommitAnimations]; } NSLog(@"Calculator%i",Calculator); }
-(void)hideAnimationStopped { NSLog(@"imageViewStop"); [imageviewtsremoveFromSuperview]; [maximgbuttonremoveFromSuperview]; maximgbutton=nil; imageviewts=nil; }
相关文章推荐
- UIImageView 与 CABasicAnimation 实现多层视图,带动画效果objec iOS
- iOS开发导航控制器下不同视图控制器之间切换:利用CATrasition和view的layer层来实现自定义的动画效果
- android 视图动画的使用,Animation重写 实现旋转效果
- 使用ObjectAnimator实现视图的动画效果(平移)
- 视图弹出后放大又缩小的动画实现、类似于alertView效果
- 【iOS开发-24】导航控制器下不同视图控制器之间切换:利用CATrasition和view的layer层来实现自定义的动画效果
- UIImageView-播放序列图(简单的动画效果实现)
- 视图动画效果 通过layer层实现
- HTML5 Canvas动画效果实现原理
- 使用CAlayer实现动画效果
- Android应用程序入门 推箱子游戏开发(一) surfaceView 实现动画效果
- jquery animate实现动画效果
- UI特效--Android利用ViewFlipper实现屏幕切换动画效果
- Android中动画效果的实现
- 使用CSS3实现超炫的Loading(加载)动画效果
- 实现视图的动画
- cocos2dx 3.x(实现帧动画(人物动画,跑马灯效果)的几种方法)
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- Android自定义viewGroup实现点击动画效果
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果