- 項目基本目錄
其中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]; }]; }