新浪微博樣式的ActionSheet
新浪微博樣式的ActionSheet
實現此功能的關鍵是在view里面生成一個UIWindow(該window會自動被加入到已有的window上面),然后設置windowlevel和hidden屬性就可以顯示或者隱藏。
//懶加載window,新建window之后會被自動添加到已有window上,只要設置windowLevel和hidden屬性即可顯示
-(UIWindow *)actionWindow{
if (!_actionWindow) {
_actionWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
_actionWindow.windowLevel = UIWindowLevelAlert;
_actionWindow.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3];
}
return _actionWindow;
}
//顯示
-(void)show{
//設置self初始位置
self.frame = CGRectMake(0, ZDHEIGHT, ZDWIDTH, ZDHEIGHT);
//添加本身到新建window
[self.actionWindow addSubview:self];
self.actionWindow.hidden = NO;
[UIView animateWithDuration:ZDANIMATIONTIME animations:^{
self.frame = CGRectMake(0, 0, ZDWIDTH, ZDHEIGHT);
}];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self dismissFromeSuperView];
}
//移除
-(void)dismissFromeSuperView {
[UIView animateWithDuration:ZDANIMATIONTIME animations:^{
self.frame = CGRectMake(0, ZDHEIGHT, ZDWIDTH, ZDHEIGHT);
} completion:^(BOOL finished) {
[self removeFromSuperview];
self.actionWindow.hidden = YES;
self.actionWindow = nil;
}];
} 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!