ios实现button变换颜色并可以放大、缩小、旋转
来源:互联网 发布:复杂网络聚类分析 编辑:程序博客网 时间:2024/05/16 01:29
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_window = [[UIWindowalloc] initWithFrame:[UIScreenmainScreen].bounds];
_window.backgroundColor = [UIColorwhiteColor];
[_windowmakeKeyAndVisible];
//定义一个父视图
UIView *superView = [[UIViewalloc] initWithFrame:CGRectMake(65,65, 300, 300)];
[_window addSubview:superView];
_views = [[NSMutableArrayalloc] init];
//循环创建七个子视图
for (int i =0; i < 7; i ++) {
UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(50,50, 250, 250)];
//设置随机色
view.backgroundColor = [UIColorcolorWithRed:arc4random()%10*.1green:arc4random()%10*.1blue:arc4random()%10*.1alpha:1];
[_window addSubview:view];
UIView *lastView = [_viewslastObject];
if (lastView != nil) {
view.transform = CGAffineTransformScale(lastView.transform,0.8, 0.8);
}
[_views addObject:view];
}
//在界面上添加几个button,来实现不同的功能
UIButton *button1 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[button1 setTitle:@"旋转"forState:UIControlStateNormal];
button1.tag = 101;
button1.frame = CGRectMake(50, 320, 50, 30);
[button1 addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[_window addSubview:button1];
UIButton *button2 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[button2 setTitle:@"放大"forState:UIControlStateNormal];
button2.tag = 102;
button2.frame = CGRectMake(150, 320, 50, 30);
[button2 addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[_window addSubview:button2];
UIButton *button3 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
[button3 setTitle:@"缩小"forState:UIControlStateNormal];
button3.tag = 103;
button3.frame = CGRectMake(250, 320, 50, 30);
[button3 addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[_window addSubview:button3];
_index = 0;
return YES;
}
//button的点击事件
- (void)buttonAction:(UIButton *)button{
if (button.tag ==103) {
for (UIView *viewin _views) {
view.transform = CGAffineTransformScale(view.transform, .5, .5);
}
}else if (button.tag ==102)
{
for (UIView *viewin _views) {
view.transform = CGAffineTransformScale(view.transform, 2, 2);
}
}else{
//开启一个定时器
[NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(timeAction:)userInfo:nilrepeats:YES];
}
}
//定时器
- (void)timeAction:(NSTimer *)time{
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1.9];
for (UIView *viewin _views) {
view.backgroundColor = [UIColorcolorWithRed:arc4random()%10*.1green:arc4random()%10*.1blue:arc4random()%10*.1alpha:1];
view.transform = CGAffineTransformRotate(view.transform,M_PI/10);
}
[UIViewcommitAnimations];
_index++;
if (_index ==10) {
for (UIView *viewin _views) {
[view removeFromSuperview];
}
[time invalidate];
}
}
- ios实现button变换颜色并可以放大、缩小、旋转
- #iOS开发笔记#UIImageView实现拖动,放大/缩小,旋转
- 猫猫学IOS(二)UI之按钮操作 点击变换 移动 放大缩小 旋转
- AJ学IOS(02)UI之按钮操作 点击变换 移动 放大缩小 旋转
- iOS点击button放大后缩小效果
- iOS点击button放大后缩小效果
- 安卓实现图片旋转放大缩小
- Inkcanvas 放大缩小变换
- android 实现可以放大缩小的TextView
- ---Transform---放大缩小旋转
- iOS开发——手势识别器(用手势实现图片旋转和缩小放大)
- textarea可以放大缩小
- iOS 侧滑栏实现的放大和缩小
- ios UIWebView捏合放大缩小的实现
- IOS代码添加控件,控件移动,放大,缩小,旋转
- IOS代码添加控件,控件移动,放大,缩小,旋转
- IOS代码添加控件,控件移动,放大,缩小,旋转
- IOS代码添加控件,控件移动,放大,缩小,旋转
- jquery中事件详解
- POJ3276---The Cow Lexicon
- json
- 5个最佳的Android测试框架(带示例)
- 使用java连接hive,并执行hive语句详解
- ios实现button变换颜色并可以放大、缩小、旋转
- 自定义cell代码创建
- 通过金矿模型介绍动态规划
- 简单了解Java
- 设计模式 - 工厂方法(Factory Method) C++实现
- 第8章-RFID防碰撞技术
- UML用例图
- 黑马程序员——面向对象(一)
- android Activity实现从右边弹出或滑出选择菜单或窗口