很多应用程序你会发现有一些固定不动的悬浮控件,例如你在滚动tableview时就会看到有固定的控件不动;
代码如下:
- (void)test{
//
UIView *view_1 = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 100, 30)];
view_1.backgroundColor = [UIColor blackColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"button" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 200, 100, 30);
button.backgroundColor = [UIColor redColor];
//把button贴在window上
[[[[UIApplication sharedApplication] windows] firstObject] addSubview:button];
//
[[[[UIApplication sharedApplication] windows] firstObject] addSubview:view_1];
//
}