簡體   English   中英

ios選項卡欄按鈕到模態視圖

[英]ios tab bar button to modal view

我正在使用idev-recipes / RaisedCenterTabBar,我想要一個從中心按鈕調用的模態視圖,而不是相機。

代碼在這里: https//github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar

關於如何使這個工作的任何想法?

為了實現這一目標,有更好的方法可以遵循。 而且更容易。

通過使用這種方法實現我的理解: https//github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar是當你試圖隱藏標簽欄時發生的奇怪事情。 所以我找到的最好的解決方案(和你一樣)就在這里: http//www.lantean.co/display-a-modal-uiviewcontroller-when-a-uitabbaritem-is-pressed/

沒有必要做任何其他事情。 只需忽略與UITabBarItem關聯的視圖控制器並顯示您的模態視圖! 就這樣!

我將創建自己的UITabBarController子類,然后添加此方法:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item  {

}

您將能夠判斷選擇了哪個項目,然后在其中實例化模態VC。

也許你可以使用UITabBarDelegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
方法。
當有人按下標簽欄中的按鈕時,該方法將被發送給委托。 在那里你可以檢查它是否是正確的按鈕,然后實例化模態視圖控制器。

通過子類化或使用委托,您只需檢查所選項目是否為中間按鈕,如果是,請使用選項卡欄選擇之前選擇的項目,然后顯示模型視圖控制器。 由於您將在原始選擇發生的相同RunLoop源中執行此操作,因此無需切換到中間VC即可有效地撤消選項卡選擇。

根據您提供的代碼示例=> https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar

中央凸起的標簽按鈕是一個UIButton,所以只需在BaseViewController.m類中設置該按鈕的動作

[button addTarget:self action:@selector(showmodalview) forControlEvents:UIControlEventTouchUpInside];

然后在showmodalview方法中編寫此代碼=>

-(void)showmodalview
{
    UIViewController *view1=[[UIViewController alloc] init]; // you can use any view controller instance you want ,this is just the example.
    [self presentModalViewController:view1 animated:YES];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM