- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton * bt = [UIButton buttonWithType:UIButtonTypeContactAdd];
bt.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:bt];
[bt addTarget:self action:@selector(btTTTClic:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)btTTTClic:(UIButton * )bt
{
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
view.tag = 200;
view.backgroundColor = [UIColor grayColor];
view.alpha = 0.8;
[[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:view];
UIButton * btt = [UIButton buttonWithType:UIButtonTypeContactAdd];
btt.frame = CGRectMake(100, 100, 100, 100);
[view addSubview:btt];
[btt addTarget:self action:@selector(btTTTCli:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)btTTTCli:(UIButton *)bt
{
UIView * view = [[UIApplication sharedApplication].delegate.window.rootViewController.view viewWithTag:200];
[UIView animateWithDuration:0.2 animations:^{
[view setFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, 0)];
} completion:^(BOOL finished) {
[view removeFromSuperview];
}];
}
核心代码 其实就一句:[[UIApplication sharedApplication].delegate.window.rootViewController.viewaddSubview:view];
和大家分享一下,同时请教大家一个问题 我敲代码的时候 部分代码不知道为什么没有提示 希望大家能留言帮忙解决一下!