- 项目基本目录
其中xib文件用来自定义需要弹出的视图。
在主控制器里设置popview的frame等信息代码如下:
底部视图(popview)初始化放在父类视图的最顶部或者说是整个屏幕的最底部,宽高自定义
- (void)viewDidLoad { [super viewDidLoad]; _popview = [[popview alloc]init]; _popview.frame = CGRectMake(0, self.view.frame.size.height, 400, 700); [self.view addSubview:_popview]; }
当点击相应按钮的时候让底部视图往上移
- (IBAction)pop:(id)sender { [ UIView animateWithDuration:0.3 animations:^{ CGAffineTransform tf = CGAffineTransformMakeTranslation(0, -_popview.frame.size.height); [_popview setTransform:tf]; }]; }
popview视图中的代码如下:
@interface popview () @property (weak, nonatomic) IBOutlet UIView *bkview; @end @implementation popview - (instancetype)init{ //从xib中初始化视图 if (self = [super init]) { NSArray *binview = [[NSBundle mainBundle] loadNibNamed:@"popview" owner:nil options:nil]; self = [binview lastObject]; } return self; } //点击取消按钮的时候移除并且让弹出视图的背景视图隐藏,等到底部视图彻底移到底部的时候在设置显示背景视图(背景视图主要用来模糊效果) - (IBAction)cancel:(id)sender { [_bkview setHidden:YES]; [UIView animateWithDuration:0.3 animations:^{ self.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { [_bkview setHidden:NO]; }]; }