IOS MenuViewController實(shí)現(xiàn)彈出菜單效果
在寫項(xiàng)目時,要實(shí)現(xiàn)一個從下移上來的一個彈出菜單,并且背景變深的這么一個效果,在此分享給大家。
主要說一下思路及一些核心代碼貼出來,要想下載源碼,請點(diǎn)擊下載:MenuViewController
一個簡單,效果好,比較實(shí)用的菜單彈出效果的實(shí)現(xiàn),效果圖:

實(shí)現(xiàn)方式:將self.view當(dāng)前頁面縮小,在當(dāng)前頁的上面添加一個菜單的view,即在self.view.superview添加。
//顯示
- (void) show:(UIView*)parent
{
parentView = parent;
//先隱藏backView,table
backView.alpha = 0;
_table.alpha = 0;
//移動table
[_table setTransform:CGAffineTransformMakeTranslation(0, _table.frame.size.height)];
//父窗口添加本view,---這個會調(diào)用viewDidLoad
[parentView.superview addSubview:self.view];
//添加動畫,添加到父窗口中,使之從下移動上
[UIView animateWithDuration:0.3 animations:^{
//父窗口縮小
CGAffineTransform t = CGAffineTransformMakeScale(0.9, 0.9);
[parentView setTransform:t];
//顯示backview,table
backView.alpha = 1;
_table.alpha = 1;
//移動table,CGAffineTransformIdentity還原原始坐標(biāo)
[_table setTransform:CGAffineTransformIdentity];
} completion:^(BOOL finished) {
}];
}
//隱藏
- (void) hide
{
//添加動畫,添加到父窗口中,使之從下移動上
[UIView animateWithDuration:0.3 animations:^{
//父窗口還原
CGAffineTransform t = CGAffineTransformIdentity;
[parentView setTransform:t];
//顯示backview,table
backView.alpha = 0;
_table.alpha = 0;
//移動table
[_table setTransform:CGAffineTransformMakeTranslation(0, _table.frame.size.height)];
} completion:^(BOOL finished) {
[self.view removeFromSuperview];
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
//背影黑罩
backView = [[UIView alloc]initWithFrame:self.view.bounds];
backView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
[self.view addSubview:backView];
//算出table的CGRect
CGRect rect = self.view.bounds;
int height = _titleArray.count * 44;
rect.origin.y = rect.size.height - height;
rect.size.height = height;
_table = [[UITableView alloc]initWithFrame:rect];
_table.delegate = self;
_table.dataSource = self;
[self.view addSubview:_table];
}
這個菜單你可以任意自定義,我這里是一個tableView,你可以寫一些有圖和文字的添加上去。只需要把源代碼稍改,就ok!
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Xcode 9下適配iPhoneX導(dǎo)致iOS 10不兼容問題的解決方法
這篇文章主要給大家介紹了關(guān)于Xcode 9下適配iPhoneX導(dǎo)致iOS 10不兼容問題的解決方法,文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04
iOS開發(fā)實(shí)戰(zhàn)之Label全方位對齊的輕松實(shí)現(xiàn)
這篇文章主要給大家介紹了關(guān)于iOS開發(fā)實(shí)戰(zhàn)之輕松實(shí)現(xiàn)Label全方位對齊的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10
IOS NSUserDefault 記住用戶名及密碼功能的實(shí)例代碼
這篇文章主要介紹了IOS NSUserDefault 記住用戶名及密碼功能的實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-09-09
IOS在SwiftUI中顯示模態(tài)視圖的實(shí)例代碼
這篇文章主要介紹了IOS在SwiftUI中顯示模態(tài)視圖的實(shí)例代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2020-02-02

