联系人:石虎 QQ: 1224614774 昵称:嗡嘛呢叭咪哄
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor whiteColor];
#warning 效果图一:
//懒加载,将切换城市按钮拿到最上层
[self.view bringSubviewToFront:self.changeCityBtn];// 将子视图在前面
#warning 效果图二:
//用第二层子视图 换 第一层子视图的位置,self.view是第0层
//[self.view exchangeSubviewAtIndex:2 withSubviewAtIndex:1];
![iOS <wbr>bringSubviewToFront和exchangeSubviewAtIndex方法应用 iOS <wbr>bringSubviewToFront和exchangeSubviewAtIndex方法应用](http://upload-images.jianshu.io/upload_images/6083675-bd65adaf3eef190e.png?imageMogr2/auto-orient/strip|imageView2/2/w/1240)
}
//changeCityBtn getter 方法实现
-(UIButton *)changeCityBtn {
if (!_changeCityBtn) {
_changeCityBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
_changeCityBtn.frame = CGRectMake(kScreenWidth-44-10,20, 44, 44);
_changeCityBtn.imageEdgeInsets = UIEdgeInsetsMake(8, 8,8, 8);
[_changeCityBtn setImage:[UIImageimageNamed:@"location_hardware"]forState:UIControlStateNormal];
[self.view addSubview:_changeCityBtn];
[_changeCityBtn addTarget:selfaction:@selector(changeCity)forControlEvents:UIControlEventTouchUpInside];
}
return _changeCityBtn;
}