首页 > 代码库 > IOS 动画
IOS 动画
//uiview动画 //开始动画 [UIView beginAnimations:nil context:nil]; //运动的时间 [UIView setAnimationDuration:2.f]; //延时启动 [UIView setAnimationDelay:2]; //速度曲线(可以改变速度) [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; //代理 [UIView setAnimationDelegate:self]; //代理方法 开始时候执行 [UIView setAnimationWillStartSelector:@selector(start)]; //结束时候执行 [UIView setAnimationDidStopSelector:@selector(stop)]; //重复执行 [UIView setAnimationRepeatAutoreverses:YES]; //重复几次 [UIView setAnimationRepeatCount:2]; //重复 [UIView setAnimationsEnabled:YES]; //翻转 [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.Testview cache:YES]; //动画过程 self.Testview.backgroundColor = [UIColor colorWithRed:arc4random()%255/256.0 green:arc4random()%255/256.0 blue:arc4random()%255/256.0 alpha:1]; //提交动画 [UIView commitAnimations];
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87);">//<span style="font-family: 'Heiti SC Light';">系统自带</span>block</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87);"> [UIView animateWithDuration:2.f animations:^{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87); min-height: 21px;"> </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87);"> }];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 18px; font-family: Menlo; color: rgb(76, 191, 87);"><pre name="code" class="objc">[UIView transitionWithView:self.view duration:2.f options:(UIViewAnimationOptionTransitionFlipFromTop) animations:^{ NSLog(@"开始动画"); self.MyView.backgroundColor = [UIColor greenColor]; } completion:^(BOOL finished) { self.MyView.backgroundColor = [UIColor orangeColor]; NSLog(@"动画结束"); }];
[UIView animateWithDuration:2.f animations:^{ // self.MyView.transform = CGAffineTransformTranslate(self.MyView.transform, 0.5f, 0.5f); self.MyView.transform = CGAffineTransformRotate(self.MyView.transform, M_PI_2); }];
<pre name="code" class="objc">//模拟自带block自己写的方法 -(void)myAnimationDuration:(NSTimeInterval)time animation:(myBlock)ani { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:time]; ani(); [UIView commitAnimations]; }
//给view设置边缘 描边粗细 self.myview.layer.borderWidth = 20; //描边颜色(注意类型转换) self.myview.layer.borderColor = [UIColor yellowColor].CGColor; //阴影偏移 self.myview.layer.shadowOffset = CGSizeMake(50, 50); //阴影颜色 self.myview.layer.shadowColor = [UIColor grayColor].CGColor; //阴影透明度 self.myview.layer.shadowOpacity = 0.8; //模糊程度 self.myview.layer.shadowRadius = 10
//第一种
<pre name="code" class="objc">CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.duration = 2.0; animation.repeatCount = 30; animation.autoreverses = YES; NSArray *array = @[[NSValue valueWithCGPoint:CGPointMake(25, 25)],[NSValue valueWithCGPoint:CGPointMake(200, 25)],[NSValue valueWithCGPoint:CGPointMake(25, 200)],[NSValue valueWithCGPoint:CGPointMake(200, 200)]]; animation.values = array; [self.myview.layer addAnimation:animation forKey:@"asd"];
//第二种
<pre name="code" class="objc">CAAnimationGroup *group = [CAAnimationGroup animation]; //1 CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; //初始值 animation1.fromValue = http://www.mamicode.com/[NSNumber numberWithFloat:0.3];>
//第三种<pre name="code" class="objc">CATransition *ani = [CATransition animation]; /* pageCurl 向上翻一页 pageUnCurl 向下翻一页 rippleEffect 滴水效果 suckEffect 收缩效果,如一块布被抽走 cube 立方体效果 oglFlip 上下翻转效果 */ ani.type = @"cube"; ani.repeatCount = 200; ani.duration = 1; //方向 ani.subtype = kCATransitionFromLeft; [self.myview.layer addAnimation:ani forKey:@"an"];IOS 动画
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。