当前位置: 首页 > news >正文

泉州专业做网站公司/国内重大新闻十条

泉州专业做网站公司,国内重大新闻十条,免费微网站开发平台,佳匠网站建设为什么80%的码农都做不了架构师?>>> 一、UIView动画的实现 UIView使用Context来实现动画 关键代码: // //参数1 动画名称 参数2 要实现动画的对象上下文 [UIView beginAnimations:"attribute" context:_showImageView];//设置动…

为什么80%的码农都做不了架构师?>>>   hot3.png

一、UIView动画的实现

    UIView使用Context来实现动画

    关键代码:

//
//参数1 动画名称 参数2 要实现动画的对象上下文
[UIView beginAnimations:@"attribute" context:_showImageView];//设置动画的时间
[UIView setAnimationDuration:1.0f];//设置动画延迟时间
// [UIView setAnimationDelay:2];//设置视图center 实现试图移动动画
_showImageView.center = CGPointMake(100, 100);//设置alpha值:视图透明度
_showImageView.alpha = 0.2f;//设置背景颜色
_showImageView.backgroundColor = [UIColor greenColor];//UIView动画 设置代理
[UIView setAnimationDelegate:self];//动画将要开始代理方法
[UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];//动画已经结束代理方法
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];//提交动画设置,执行动画
[UIView commitAnimations];


    使用Block实现的动画:

//
//UIView动画,使用Block实现
[UIView animateWithDuration:1.0f animations:^{//通过设置translation 实现视图的偏移if ([self.mySwitch isOn]) {//基于上一次的translation_showImageView.transform = CGAffineTransformTranslate(_showImageView.transform, 50, 0);} else {//基于原始的translation_showImageView.transform = CGAffineTransformMakeTranslation(-50, 0);}
}];

二、一个例子使用animation(包括上下左右移动,旋转,放大缩小)

    a、首先用storybroad布局好一个页面,并给各个按钮设置tag

    202002_IxBP_1444783.png

   (1)图中的图片是一个按钮,点击后可重置位置

    (2)蓝色按钮可改变图片的frame

    (3)橘色按钮可改变图片的transform

    绑定对象和事件后是这样:

    202304_p04Q_1444783.png

    (1)蓝色的四个按钮都绑定了move方法

    (2)橘色的四个按钮都绑定了transform方法

    (3)暂时不用管上面的imageView变量,后面会有用处的

    先来解决move方法吧:

#pragma mark 移动
- (IBAction)move:(id)sender {[UIView animateWithDuration:1.0f animations:^{CGRect frame = _image.frame;frame.origin.y -= 50;_image.frame = frame;}];
}

    好了,成功移动图片了,这时我们可以用switch来实现上下左右移动

    注意,id类型的sender是不能用点语法,即sender.tag是会报错的,应该使用[sender tag]

#pragma mark 移动
- (IBAction)move:(id)sender {[UIView animateWithDuration:1.0f animations:^{CGRect frame = _image.frame;switch ([sender tag]) {case 1:    // 上frame.origin.y -= 50;break;case 2:    // 下frame.origin.y += 50;break;case 3:    // 左frame.origin.x -= 50;break;case 4:    // 右frame.origin.x += 50;break;default:break;}_image.frame = frame;}];
}

    接下来是transform方法,类似move方法:

#pragma mark 变化
- (IBAction)transform:(id)sender {
//    // 不会在原有基础上继续变化,M_PI_4表示math中的π/4,M_4_PI则表示math的4π
//    _image.transform = CGAffineTransformMakeRotation(-M_PI_4);[UIView animateWithDuration:1.0f animations:^{switch ([sender tag]) {case 5:    // 左转_image.transform = CGAffineTransformRotate(_image.transform, -M_PI_4);break;case 6:    // 右转_image.transform = CGAffineTransformRotate(_image.transform, M_PI_4);break;case 7:    // 放大_image.transform = CGAffineTransformScale(_image.transform, 2.0, 2.0);break;case 8:    // 缩小_image.transform = CGAffineTransformScale(_image.transform, 0.5, 0.5);default:break;}} completion:^(BOOL finished) {NSLog(@"动画完成");}];
}

    然后问题就来了,你会发现旋转时图片不是按照center中心来旋转,它按照左上角旋转了!

    三种办法解决:

    (1)去掉autolayout

    (2)如果一定要autolayout,则取消image的autolayout

            _image.translatesAutoresizingMaskIntoConstraints = YES;

    (3)给image设置一个父view,并使用autolayout居中于它,这就是之前的.h文件中imageView的作用了,我把它设置成蓝色,旋转后便可看到

        204822_elAu_1444783.png

    move方法则最好把之前的_image移动改成_imageView移动

#pragma mark 移动
- (IBAction)move:(id)sender {[UIView animateWithDuration:1.0f animations:^{CGRect frame = _imageView.frame;switch ([sender tag]) {case 1:    // 上frame.origin.y -= 50;break;case 2:    // 下frame.origin.y += 50;break;case 3:    // 左frame.origin.x -= 50;break;case 4:    // 右frame.origin.x += 50;break;default:break;}_imageView.frame = frame;}];
}

    最后是reset方法:    

#import "ViewController.h"@interface ViewController ()
@property (nonatomic) CGRect frame;
@end@implementation ViewController#pragma mark view load
- (void)viewDidLoad {_frame = _imageView.frame;
}#pragma mark 重置
- (IBAction)reset:(id)sender {[UIView animateWithDuration:1.0f animations:^{_image.transform = CGAffineTransformIdentity;_imageView.frame = _frame;}];
}








转载于:https://my.oschina.net/cobish/blog/346084

http://www.lbrq.cn/news/1081981.html

相关文章:

  • 方圆网站建设/产品关键词大全
  • 上海网站制作是什么/电商运营是做什么的
  • 移动网站 案例/2022百度seo优化工具
  • 哪个网站帮忙做户型方案/网站seo策划方案
  • 公司公众号怎么制作/seo优化入门教程
  • 西安网站制作开发公司哪家好/扬州seo
  • 帝国cms如何做网站/百度关键词排名批量查询
  • 教怎么做ppt的网站/app接入广告变现
  • 漯河网站建设网站建设/纯注册app拉新平台
  • 做网站需要机吗/国外网站加速
  • 网站建设人员要求/网站模板购买
  • 不用编程做网站/上海网站建设
  • 江苏省水利工程建设局网站/站长之家爱站网
  • 网站怎么做ipfs/外链兔
  • 网站开场flash怎么做的/上海百度竞价点击软件
  • v2ex 网站建设/廊坊网络推广公司
  • 网站设计哪家专业/网络营销软文范例500字
  • 南昌建站费用/友情链接获取的途径有哪些
  • 衡水企业做网站费用/百度站长平台账号购买
  • wordpress webfont/热狗网站关键词优化
  • wordpress po翻译/谷歌seo优化
  • 在洪雅网站做企业招聘/网页制作公司排名
  • 两学一做网站注册/百度一下百度网页版进入
  • 有哪些做短租的网站好/关键词排名优化
  • wordpress快速仿站/搜索引擎广告形式有
  • 安卓ui用什么软件设计/怎样优化网站
  • 企业移动网站建设/seo教程seo官网优化详细方法
  • 时间轴网站设计/微软优化大师
  • 深圳做网站要多少钱/线上营销方式
  • 网站注册平台/十大广告公司排名
  • 让 OAuth 授权码流程更安全的 PKCE 技术详解
  • 嵌入式教学的云端革命:高精度仿真如何重塑倒车雷达实验与工程教育——深圳航天科技创新研究院赋能新一代虚实融合实训平台
  • es的histogram直方图聚合和terms分组聚合
  • 【运维基础】Linux 进程调度管理
  • 如何解决人工智能在社会治理中面临的技术和伦理挑战?
  • Linux安装ragflow(含一键安装脚本)