溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

IOS中MenuViewController如何實現(xiàn)彈出菜單效果

發(fā)布時間:2021-07-09 09:32:56 來源:億速云 閱讀:124 作者:小新 欄目:移動開發(fā)

這篇文章主要介紹IOS中MenuViewController如何實現(xiàn)彈出菜單效果,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

效果圖:

IOS中MenuViewController如何實現(xiàn)彈出菜單效果

實現(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!

以上是“IOS中MenuViewController如何實現(xiàn)彈出菜單效果”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

ios
AI