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

做网站一定需要自己买主机吗站长工具官网查询

做网站一定需要自己买主机吗,站长工具官网查询,wordpress添加文章关键词描述,南阳做网站优化的公司需求 基于上一节代码进行精简,降低了冗余性。添加动画,使得坐标变化自然,同时使用了bounds属性和center属性,使得UIView变化以中心点为基准。 此外,使用两种方式添加动画:1.原始方式。 2.block方式。 代码…

需求

基于上一节代码进行精简,降低了冗余性。添加动画,使得坐标变化自然,同时使用了bounds属性和center属性,使得UIView变化以中心点为基准。
此外,使用两种方式添加动画:1.原始方式。 2.block方式。

代码实现

@interface UIButtonTest1 : UIView@property(strong, nonatomic) UIButton *btn;
@property(strong, nonatomic) UIButton *btn1;
@property(strong, nonatomic) UIButton *btn2;
@property(strong, nonatomic) UIButton *btn3;
@property(strong, nonatomic) UIButton *btn4;
@property(strong, nonatomic) UIButton *btn5;
@property(strong, nonatomic) UIButton *btn6;@end
#import "UIButtonTest1.h"@implementation UIButtonTest1-(instancetype) initWithFrame:(CGRect)frame{self = [super initWithFrame:frame];// 视图中有个按钮,按钮点击了没反应?GPT4实现一下if(self){_btn = [[UIButton alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];[_btn setTitle:@"点击前" forState:UIControlStateNormal];// 文字设置[_btn setTitleColor:[UIColor blackColor]  forState:UIControlStateNormal];// bgImage[_btn setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];// 动画:绑定函数,点击事件,在btn上调用,加到self上[_btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];/// btn1~6 初始化和设置大小_btn1 = [[UIButton alloc] initWithFrame:CGRectMake(80, 350, 50, 50)];_btn2 = [[UIButton alloc] initWithFrame:CGRectMake(80, 400, 50, 50)];_btn3 = [[UIButton alloc] initWithFrame:CGRectMake(30, 400, 50, 50)];_btn4 = [[UIButton alloc] initWithFrame:CGRectMake(130, 400, 50, 50)];_btn5 = [[UIButton alloc] initWithFrame:CGRectMake(200, 349, 49, 49)];_btn6 = [[UIButton alloc] initWithFrame:CGRectMake(200, 402, 49, 49)];/// 设置背景图片[_btn1 setBackgroundImage:[UIImage imageNamed:@"shang.jpg"] forState:UIControlStateNormal];[_btn2 setBackgroundImage:[UIImage imageNamed:@"xia.jpg"] forState:UIControlStateNormal];[_btn3 setBackgroundImage:[UIImage imageNamed:@"zuo.jpg"] forState:UIControlStateNormal];[_btn4 setBackgroundImage:[UIImage imageNamed:@"you.jpg"] forState:UIControlStateNormal];[_btn5 setBackgroundImage:[UIImage imageNamed:@"jia.jpg"] forState:UIControlStateNormal];[_btn6 setBackgroundImage:[UIImage imageNamed:@"jian.jpg"] forState:UIControlStateNormal];// 设置不同tag以区分不同按钮_btn1.tag = 1;_btn2.tag = 2;_btn3.tag = 3;_btn4.tag = 4;_btn5.tag = 5;_btn6.tag = 6;/// 绑定函数:按钮的反应函数都绑定到同一个函数上/// 有参数这里要加:吗
//        [_btn1 addTarget:self action:@selector(btn1Clicked:) forControlEvents:UIControlEventTouchUpInside];
//        [_btn2 addTarget:self action:@selector(btn1Clicked:) forControlEvents:UIControlEventTouchUpInside];
//        [_btn3 addTarget:self action:@selector(btn1Clicked:) forControlEvents:UIControlEventTouchUpInside];
//        [_btn4 addTarget:self action:@selector(btn1Clicked:) forControlEvents:UIControlEventTouchUpInside];
//        [_btn5 addTarget:self action:@selector(btn1Clicked:) forControlEvents:UIControlEventTouchUpInside];
//        [_btn6 addTarget:self action:@selector(btn1Clicked:) forControlEvents:UIControlEventTouchUpInside];
//        // 绑定第二种[_btn1 addTarget:self action:@selector(btn2Clicked:) forControlEvents:UIControlEventTouchUpInside];[_btn2 addTarget:self action:@selector(btn2Clicked:) forControlEvents:UIControlEventTouchUpInside];[_btn3 addTarget:self action:@selector(btn2Clicked:) forControlEvents:UIControlEventTouchUpInside];[_btn4 addTarget:self action:@selector(btn2Clicked:) forControlEvents:UIControlEventTouchUpInside];[_btn5 addTarget:self action:@selector(btn2Clicked:) forControlEvents:UIControlEventTouchUpInside];[_btn6 addTarget:self action:@selector(btn2Clicked:) forControlEvents:UIControlEventTouchUpInside];// 初始化btn2、btn3、btn4、btn5// 本身是view,需要添加组件进去[self addSubview:_btn];[self addSubview:_btn1];[self addSubview:_btn2];[self addSubview:_btn3];[self addSubview:_btn4];[self addSubview:_btn5];[self addSubview:_btn6];}return self;
}// 带图片的按钮点击后的变化
// 点击后重新设置title、bgImage
- (void)btnClicked{// 点击前后static BOOL isClicked = NO;if(isClicked){[_btn setTitle:@"点击前" forState:UIControlStateNormal];[_btn setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];}else{// 状态常识不同样式:hightlight,可设置[_btn setTitle:@"点击后" forState:UIControlStateNormal];[_btn setBackgroundImage:[UIImage imageNamed:@"2.jpg"] forState:UIControlStateNormal];}isClicked = !isClicked;
}// 增加动画:以原始坐标变化
- (void)btn1Clicked:(UIButton *)sender{// 获取原始frameCGRect originalFrame = self.btn.frame;switch (sender.tag) {case 1:originalFrame.origin.y -= 100;break;case 2:originalFrame.origin.y += 100;break;case 3:originalFrame.origin.x -= 100;break;case 4:originalFrame.origin.x += 100;break;case 5:originalFrame.size.width += 100;originalFrame.size.height += 100;break;case 6:originalFrame.size.width -= 100;originalFrame.size.height -= 100;break;}// ==== 改:动画 ====// 开启[UIView beginAnimations:nil context:nil];// 设置动画时间[UIView setAnimationDuration:2];// 要执行的动画self.btn.frame = originalFrame;[UIView commitAnimations];// 发现就是在frame变化的前后增加动画开启、设置动画时长和关闭设置
}// 增加动画:以中心点变化
// center:更改放大缩小,移动看不出的
- (void)btn2Clicked:(UIButton *)sender{// 获取原始frame:中心变化center用这个CGPoint centerPoint = self.btn.center;CGRect originBounds = self.btn.bounds;switch (sender.tag) {case 1:centerPoint.y -= 100;break;case 2:centerPoint.y += 100;break;case 3:centerPoint.x -= 100;break;case 4:centerPoint.x += 100;break;case 5:originBounds.size.width += 100;originBounds.size.height += 100;break;case 6:originBounds.size.width -= 100;originBounds.size.height -= 100;break;}// ==== 改:动画 ====// 开启[UIView beginAnimations:nil context:nil];// 设置动画时间[UIView setAnimationDuration:2];// 要执行的动画self.btn.center = centerPoint;self.btn.bounds = originBounds;[UIView commitAnimations];// 发现就是在frame变化的前后增加动画开启、设置动画时长和关闭设置
}@end

其实点击后的按钮变化可以通过设置普通状态和高亮状态来做切换,以上代码是按监听后状态变化来实现的

  1. 将各事件响应函数封装到了一起,需要利用tag属性。
  2. @selector()绑定函数时,如果有参数,需要加冒号,如果没有参数,直接加名字即可。
  3. center和bounds的初始化类和frame不同,要注意

以上为头尾式实现添加动画,下面使用block方式添加动画。

使用block方式实现动画

// 使用block方式
[UIView animateWithDuration:1.0 animations:^{self.btn.frame = originalFrame;
}]

复习OC的block
这是一种函数调用的简写方式

http://www.khdw.cn/news/55407.html

相关文章:

  • 重庆市工程建设信息关键词优化顾问
  • 本科毕业论文答辩稿网站开发腾讯企点app
  • 那个网站教宝妈做辅食公司页面设计
  • 新疆交通建设管理局网站管网人员优化是什么意思
  • 工信部企业网站认证页优化软件
  • 苏州公司网站建设百度刷排名百度快速排名
  • 信誉好的武进网站建设免费的网络推广有哪些
  • 企业做网站还是做平台好产品软文案例
  • 中国做网站知名的公司怎么提高百度搜索排名
  • 视频网站管理系统常见的网站推广方法
  • 电商网站更适合排名怎么优化快
  • 有哪些小公司网站新手如何做网上销售
  • 网站页面报价公司全网推广
  • 定制网站要多少钱搜索引擎关键词的工具
  • 做网站步骤百度联系方式
  • 2017年政府网站建设seo外包一共多少钱
  • 西藏城乡住房建设厅网站企业培训课程名称大全
  • wordpress最大负载seo入门书籍推荐
  • 做网站的公司算外包公司吗青岛seo霸屏
  • 找最新游戏做视频网站seo关键词的优化技巧
  • 网站开发目前用的是什么语言网络营销模式案例
  • 公司网站手机版模板宁阳网站seo推广
  • 网站要精细是什么意思网络营销的具体形式种类
  • 上海网站审核客服公司可以免费发外链的论坛
  • 凡科网可以免费做网站吗谷歌seo价格
  • 微网站和web网站首页个人网络销售平台
  • 网站品牌形象设计怎么做广告营销案例100例
  • 网站管理系统后台seo品牌
  • 网站建设是属于虚拟产品吗网站推广多少钱一年
  • 广州网站建设流程关键词seo价格