所有的基础动画都给予UIView一个基础的方法:animateWithDuration。 这个方法可以包含一个代码块,里面设置要改变的东西,在执行的时候iOS会自动以动画的形式展现出来,代码如下: [UIView animateWithDuration:1 animations:^{ 很简单,在上面的代码块的位置改变方块的中心就好了,如下: [UIView animateWithDuration:1 animations:^{ // 改变蓝色方块的位置 此外,还可以延迟动画的执行时间,比如想延迟半秒后执行,那么还是同样的方法,但是参数要多一点: [UIView animateWithDuration:1 delay:0.5 options:nil 透明度动画 假设我们想通过动画渐变一个控件的透明度,比如慢慢变成基本看不见,也很简单,还是那个方法: // 开始透明度动画(一秒完成) [UIView animateWithDuration
CGFloat initialDelay = 1.0f; CGFloat stutter = 0.3f; // 动画箭头图片 [UIView animateWithDuration:2.1 delay arrowView setFrame:CGRectMake(0, 0, windowWidth, 45)]; } completion:NULL]; // 动画Ministry of Fun文字 [UIView animateWithDuration [UIView animateWithDuration:2.1 delay:initialDelay + (2 * stutter) usingSpringWithDamping:0.6 initialSpringVelocity animations:^{ [addButton setFrame:CGRectMake(0, 102, windowWidth, 45)]; } completion:NULL]; [UIView animateWithDuration animations:^{ [firstRow setFrame:CGRectMake(0, 170, windowWidth, 80)]; } completion:NULL]; [UIView animateWithDuration
二、UIView动画的几个方法 + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations 例如在1S内将view渐变透明: [UIView animateWithDuration:1 animations:^{ _myView.alpha=0; }]; + (void )animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void 设置一个执行时间和一个执行动作,第二个block块中可以添加一个动画执行结束后的动作,作为补充,例如下面代码的效果,在1S内将view渐变为透明,动画结束后,view在瞬间变回不透明: [UIView animateWithDuration + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping
UIView setAnimationDuration:2.0]; /* 需要执行动画的代码 */ //提交动画 [UIView commitAnimations]; 方式2:block式 [UIView animateWithDuration options:kNilOptions animations:^{ /* 需要执行动画的代码 */ } completion:nil]; // 1s后,再执行动画(动画持续2s) [UIView animateWithDuration afterDelay:self.imageView.animationDuration]; 更新View动画 让 self.view 以及它的所有子控件强制更新的动画 //利用 2 秒的时间去更新 [UIView animateWithDuration
[self addSubview:closeBtn]; } //关闭页面 - (void)closeBtnClicked:(UIButton*)sender{ [UIView animateWithDuration CGAffineTransformScale(CGAffineTransformIdentity, 0.3, 0.3); } completion:^(BOOL finished) { [UIView animateWithDuration self.blockCloseClicked(self.hidden); }]; } //点击背景隐藏界面 - (void)tapClose{ [UIView animateWithDuration CGAffineTransformIdentity, 1.0, 1.0); } completion:^(BOOL finished) { [UIView animateWithDuration CGAffineTransformIdentity, 0.3, 0.3); } completion:^(BOOL finished) { [UIView animateWithDuration
[self addSubview:closeBtn]; } //关闭页面 - (void)closeBtnClicked:(UIButton*)sender{ [UIView animateWithDuration CGAffineTransformScale(CGAffineTransformIdentity, 0.3, 0.3); } completion:^(BOOL finished) { [UIView animateWithDuration self.blockCloseClicked(self.hidden); }]; } //点击背景隐藏界面 - (void)tapClose{ [UIView animateWithDuration CGAffineTransformIdentity, 1.0, 1.0); } completion:^(BOOL finished) { [UIView animateWithDuration CGAffineTransformIdentity, 0.3, 0.3); } completion:^(BOOL finished) { [UIView animateWithDuration
这些方法是: animateWithDuration:animations: animateWithDuration:animations:completion: animateWithDuration 因此,您可以使用这些方法创建一个包含对多个view进行更改的动画 [UIView animateWithDuration:1.0 animations:^{ firstView.alpha 如果要更改默认的动画参数,则必须使用animateWithDuration:delay:options:animations:completion:方法来执行动画。 默认情况下,嵌套动画会继承父级的持续时间和动画曲线,但即使这些选项可以根据需要被覆盖 [UIView animateWithDuration:1.0 delay: 1.0 [UIView animateWithDuration:1.0 delay:0.0 options: UIViewAnimationOptionCurveLinear animations
getValue(&time) //重设约束 textViewBottom.constant = height //动画展示 UIView.animateWithDuration :NSTimeInterval=0 value2.getValue(&time) textViewBottom.constant = 0 UIView.animateWithDuration textFieldHeight.constant = 37 textViewHeight.constant = 53 UIView.animateWithDuration textFieldHeight.constant = height textViewHeight.constant = height+16 UIView.animateWithDuration textFieldHeight.constant = 100 textViewHeight.constant = 116 UIView.animateWithDuration
1 // 没有隐藏 && flag // 需要隐藏 && offsetY > 0 // 处理顶部下拉回弹 ) { [UIView animateWithDuration scrollView.mj_footer.state == MJRefreshStateNoMoreData // 没有更多数据 )) { [UIView animateWithDuration
animationDuration:(NSTimeInterval)timer animationBlock:(QuitRentAnimationBlock)block { [UIView animateWithDuration QuitRentAnimationBlock)block { view.transform = CGAffineTransformMakeScale(1.0, 1.0); [UIView animateWithDuration 1.2); }completion:^(BOOL finish){ [UIView animateWithDuration CGAffineTransformMakeScale(0.9, 0.9); }completion:^(BOOL finish){ [UIView animateWithDuration animationDistance:(CGFloat)animationDistance animationBlock:(QuitRentAnimationBlock)block { [UIView animateWithDuration
animation2.gif [UIView animateWithDuration:3.0 animations:^{ squareView.frame = CGRectMake(50 比如这样: [UIView animateWithDuration:3.0 animations:^{ squareView.frame = CGRectMake(50, 50, 100 , 100); } completion:^(BOOL finished) { [UIView animateWithDuration:1.0 animations:^{ 示例代码: [UIView animateWithDuration:3.0 delay:0 options:UIViewAnimationOptionCurveLinear animations animation.gif 示例代码: [UIView animateWithDuration:0.7 delay:0.0 usingSpringWithDamping:0.5 initialSpringVelocity
[self.view addSubview:destinationSnapshot]; // 3 sourceView.hidden = YES; [UIView animateWithDuration removeFromSuperview]; // 4 [UIView animateWithDuration snapShot.backgroundColor = [UIColor whiteColor]; [self.view addSubview:snapShot]; [UIView animateWithDuration CGAffineTransformMakeScale(1.05, 1.05); snapShot.alpha = 0.98; } completion:^(BOOL finished) { [UIView animateWithDuration
做动画 在 iOS 4.0 以后, 引入了代码块 (code block) 的概念, 可以使用代码块来初始化动画, 这也是在 iOS 4.0 之后苹果推荐的做法, iOS SDK 提供的 API 如下: animateWithDuration :animations: animateWithDuration:animations:completion: animateWithDuration:delay:options:animations: 0.0f; this.SecondView.Alpha = 1.0f; }); 这样就实现了一个简单的渐变动画, 并且只能运行一次, 通常不能满足需求, 再来一个复杂点儿的: [UIView animateWithDuration 例如: [UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveEaseOut animations :^{ self.firstView.alpha = 0.0f; // 这里开始一个新的动画 [UIView animateWithDuration:1.0
removeFromSuperview]; } __block CustomAlertView * SELF = self; [UIView animateWithDuration CGAffineTransformIdentity,0.5, 0.5); }completion:^(BOOL finished) { [UIView animateWithDuration } completion:^(BOOL finished) { [UIView animateWithDuration break; default: break; } } // 取消视图 - (void)dismissAlertView{ [UIView animateWithDuration
UIView动画 @interface UIView(UIViewAnimationWithBlocks) + (void)animateWithDuration:(NSTimeInterval)duration animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); + (void)animateWithDuration ^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0 + (void)animateWithDuration (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL + (void)animateWithDuration sharedApplication].keyWindowaddSubview:self]; //这里是展示customView的时候的动画,可根据自己的情况自定义 [UIView animateWithDuration
键盘出现隐藏事件 -(void)keyHiden:(NSNotification *)notification { // self.tooBar.frame = rect; [UIView animateWithDuration objectForKey:@"UIKeyboardFrameEndUserInfoKey"]CGRectValue]; // self.tooBar.frame = rect; [UIView animateWithDuration
所以,我们需要使用下面的方法来实现这个效果: [UIView animateWithDuration: 0.5 delay: 0.35 options: UIViewAnimationOptionCurveEaseInOut animations: ^{ self.password.center = passwordCenter; } completion: ^(BOOL finished) { [UIView animateWithDuration ]; [self animatedView: _view4]; //y轴上移动视图上升250 - (void)animatedView: (UIView *)view { [UIView animateWithDuration 这里用到了一个新的动画API方法,transitionWithView: duration: options: animations: completion:,这个方法跟上面的animateWithDuration 因此,我们需要其他的动画方式,系统也正好提供了这样的一种动画供我们使用: + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval
CGRectValue() { UIView.animateWithDuration(0.25, animations: { CGRectValue() { UIView.animateWithDuration(0.25, animations: { self.view.frame.origin.y
[self.layer setAnchorPoint: CGPointMake(1.0f, 0.0f) ]; self.frame = oldFrame; [UIView animateWithDuration MemberCardMenuView 提供一个动画的实例方法 self.cover.hidden = NO; self.cover.alpha = 0; [UIView animateWithDuration )foldView{ /* (0,0) 为左上角,(0,1) 为左下角, (1, 0)右上, (1,1) 右下 */ [UIView animateWithDuration
(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { // 更新约束 [UIView animateWithDuration cyan setNeedsLayout]; // 通知约束更新 [cyan layoutIfNeeded]; }]; // 将现有的约束全部移除 [UIView animateWithDuration