很多應(yīng)用程序你會(huì)發(fā)現(xiàn)有一些固定不動(dòng)的懸浮控件,例如你在滾動(dòng)tableview時(shí)就會(huì)看到有固定的控件不動(dòng);
紅色是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];
//
}