很多應用程序你會發現有一些固定不動的懸浮控件,例如你在滾動tableview時就會看到有固定的控件不動;
紅色是button,黑色是view
代碼如下:
- (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];
//
}