您的位置:首页 > 产品设计 > UI/UE

IOS笔记1 UIViewAnimation 向y移动

2016-07-29 11:21 381 查看
                                                                                                         
        UIViewAnimation

      一款APP的成功与否,除了完善的功能外,用户体验也占有极大的比重,动画的合理运用,可以很好的增强用户体验。iOS开发中,常用的动画处理有UIView动画编程和核心动画编程,其中UIView动画使用简便,开发中应用十分广泛

#import "MJViewController.h"

@interface MJViewController()

@end

@implementation MJViewController

-(IBAction)up:(id)sender{

//oc语法规定:不允许直接修改 某个对象中结构体属性的成员

//0.动画(头部-开始动画)
[UIView beginAnimations:nil context:nil];

//设置动画执行时间
[UIView setAnimationDuration:2.0];

//线取出frame
CGRect tempFrame = _btn.frame;

//修改y值
tempFrame.origin.y -= 50;

//重新赋值按钮的frame
_btn.frame = tempFrame;

//4.动画(尾部提交动画--执行动画)
[UIView commitAnimations];

}

-(IBAction)run:(id) sender{
//0.动画(头部一开始动画)
[UIView beginAnimations:nil context:nil];
//设置动画执行时间
[UIView setAnimationDuration:1.0];

//先取出标记
CGRect tempFrame = _btn.frame;

//取出按钮tag标记
int tag = [sender tag];

//取出tag标记
CGFloat delta = 100;
switch(tag){
case 1://上
tempFrame.origin.y -= delta;
break;

case 2: //右
tempFrame.origin.x += delta;
break;

case 3://下
tempFrame.origin.y += delta;
break;

case 4://左
tempFrame.origin.x -= delta;
break;

default:
break;
}
//重新赋值按钮的frame
_btn.frame = tempFrame;

[UIView commitAnimations];
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UIView ios 动画 移动