绘图 - 9
来源:互联网 发布:闲杂软件 编辑:程序博客网 时间:2024/05/17 06:04
- (void)bringSubviewToFront:(UIView *)view;- (void)sendSubviewToBack:(UIView *)view;
接触到两个UIView方法,看文档的意思就是将视图放在“前后”或者是“后面”。避免了被遮挡的情况。
#import "LBDrawing2Controller.h"@interface LBDrawing2Controller ()@property (nonatomic, strong) UIView* blockedView;@property (nonatomic, strong) UIView* blockingView;@end@implementation LBDrawing2Controller- (void)viewDidLoad{ [super viewDidLoad]; [self.view setBackgroundColor:[UIColor redColor]]; UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setFrame:CGRectMake(0, 0, 50, 50)]; [button setCenter:self.view.center]; [button setTitle:@"改" forState:UIControlStateNormal]; [button setBackgroundColor:[UIColor blackColor]]; [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; UIButton* button1 = [UIButton buttonWithType:UIButtonTypeCustom]; [button1 setFrame:CGRectMake(0, 0, 50, 50)]; [button1 setCenter:CGPointMake(self.view.center.x, button.frame.origin.y + 80)]; [button1 setTitle:@"改" forState:UIControlStateNormal]; [button1 setBackgroundColor:[UIColor blueColor]]; [button1 addTarget:self action:@selector(button1Clicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button1]; self.blockedView = [[UIView alloc] init]; [self.blockedView setFrame:CGRectMake(0, 0, 80, 80)]; [self.blockedView setBackgroundColor:[UIColor yellowColor]]; [self.view addSubview:self.blockedView]; self.blockingView = [[UIView alloc] init]; [self.blockingView setFrame:CGRectMake(0, 0, 100, 100)]; [self.blockingView setBackgroundColor:[UIColor greenColor]]; [self.view addSubview:self.blockingView]; }- (void)buttonClicked:(id)sender{ UIButton* button = (UIButton*)sender; button.selected = !button.isSelected; if (button.isSelected) { [self.view sendSubviewToBack:self.blockingView]; } else { [self.view sendSubviewToBack:self.blockedView]; }}- (void)button1Clicked:(id)sender{ UIButton* button = (UIButton*)sender; button.selected = !button.isSelected; if (button.isSelected) { [self.view bringSubviewToFront:self.blockedView]; } else { [self.view bringSubviewToFront:self.blockingView]; }}
效果:
0 0
- 绘图 - 9
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 绘图
- 学习salt的源码2-run_job
- kali攻防第11章 攻击实例讲解-ms10_046快捷方式图标漏洞
- PHP接口与继承的简单实例
- OSCtxSW()函数在80x86上移植的理解
- C语言中的柔性数组
- 绘图 - 9
- 101,使用Category给API里面的类添加新方法
- Android ListView下拉/上拉刷新:设计原理与实现
- OpenSSL-0.9.8g 安装与配置指南
- 论文次序哪个为准
- 如何把前台传的两个date类型在js中转换成天
- 黑马程序员 - OC语言 - NSString前后缀检查及搜索
- SD卡分区创建详细教程
- spring mvc 框架项目tomcat 移植到WebSphere