文章实现iOS弹出式效果,有阴影有透明度。
方法一:
项目中引入YZSheetView.h,YZSheetView具体实现如下。
YZSheetView.h
#import <UIKit/UIKit.h>
@interface YZSheetView : UIActionSheet
@property (retain,nonatomic)UIView *contentView;
- (void)disMissView;
@end
#import "YZSheetView.h"
@implementation YZSheetView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame
{
if (self == [superinitWithFrame:frame])
{
[selfinitContent];
}
returnself;
}
- (void)initContent
{
self.frame =CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
//alpha 0.0 白色 alpha 1:黑色 alpha 0~1:遮罩颜色,逐渐
self.backgroundColor = [UIColorcolorWithRed:0green:0blue:0alpha:0.4];
self.userInteractionEnabled =YES;
[selfaddGestureRecognizer:[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(disMissView)]];
if (_contentView ==nil)
{
_contentView = [[UIViewalloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT - 384-69,SCREEN_WIDTH,384)];
_contentView.backgroundColor = [UIColorredColor];
[selfaddSubview:_contentView];
}
}
- (void)loadMaskView
{
}
//展示从底部向上弹出的UIView(包含遮罩)
- (void)showInView:(UIView *)view
{
if (!view)
{
return;
}
[view addSubview:self];
[view addSubview:_contentView];
[_contentViewsetFrame:CGRectMake(0,SCREEN_HEIGHT,SCREEN_WIDTH,384)];
[UIViewanimateWithDuration:0.3animations:^{
self.alpha =1.0;
[_contentViewsetFrame:CGRectMake(0,SCREEN_HEIGHT - 384-69,SCREEN_WIDTH,384)];
} completion:nil];
}
//移除从上向底部弹下去的UIView(包含遮罩)
- (void)disMissView
{
[_contentViewsetFrame:CGRectMake(0,SCREEN_HEIGHT - 384-69,SCREEN_WIDTH,384)];
[UIViewanimateWithDuration:0.3f
animations:^{
self.alpha =0.0;
[_contentViewsetFrame:CGRectMake(0,SCREEN_HEIGHT,SCREEN_WIDTH,384)];
}
completion:^(BOOL finished){
[selfremoveFromSuperview];
[_contentViewremoveFromSuperview];
}];
}
@end
_tfSheetView = [[YZSheetViewalloc]init];
[_tfSheetView.contentViewaddSubview:orderDetView];
priceLabel.text = [NSStringstringWithFormat:@"%@元",self.totalprice];
显示:[_tfSheetViewshowInView:self.view];
[_tfSheetViewdisMissView];
pod 'SnailPopupController','~> 2.0.5'
- (IBAction)filtAction:(id)sender {
filtView.frame =CGRectMake(70,0, SCREEN_WIDTH-70,SCREEN_HEIGHT);
self.sl_popupController = [SnailPopupControllernew];
self.sl_popupController.layoutType =PopupLayoutTypeRight;
self.sl_popupController.allowPan =YES;
[self.sl_popupControllerpresentContentView:filtView];
}
- (IBAction)cancelFlitAction:(id)sender {
[self.sl_popupControllerdismiss];
}