2013-03-28 44 views
3

我該如何去做這件事?我知道我必須給popover一個視圖控制器來構建它的視圖,但我不知道如何在Interface Builder中構造這個視圖(比如添加標籤和按鈕以及什麼)。在Interface Builder中爲Iphone創建彈窗視圖控制器

我只是在正常的故事板上做故事板,並且有一個故事板,它隨機沒有連接到其他任何東西,坐在角落裏?

我是否創建另一個故事板?

即使我的項目都是故事板,我還會創建xib嗎?

我是否以編程方式創建它?

+0

難道會是從你的應用中的很多地方展示,或者只有一個? – jrturton

+0

只有一個地方。 –

回答

8

因爲你沒有指定的目標設備在你的問題,我給你的Ipad答案

IPAD:

轉到你的故事板拖放viewcontrollertableviewcontroller它取決於你。然後在您的故事板上創建一個從想要的viewcontroller到最近拖/放viewcontroller的繼續。選擇你的segue爲popOver

enter image description here

enter image description here

確保你選擇像上面的圖片賽格瑞設置錨。然後你需要編輯你的popover的大小。如果其uiviewcontroller選擇其視圖,則其tableviewcontroller在界面構建器的左側選擇其桌面視圖並編輯其大小。

第一:

enter image description here

二:

enter image description here

是定製你的酥料餅的視圖控制器後(拖/下降視圖控制器)添加按鈕,任何你想要的標籤。

如果你打算在彈出窗口中做更多的事情: 不要忘記創建新文件 - > uiviewcontroller或uitableviewcontroller的子類。然後將它與故事板上新創建的視圖控制器相關聯。

enter image description here

IPHONE:

有在iphone沒有酥料餅控制器

但您嘗試使用第三方https://github.com/50pixels/FPPopover解決方案,模擬酥料餅在iphone行爲使用QuartzCore

我會嘗試以下方法:

第一:

再次拖放uiviewcontoller到故事板,然後創建一個新的文件 - >的uiviewcontroller子類。

這個新uiviewcontroller將坐在角落裏的故事板

然後在新創建的文件,你的故事板UIViewController中相關聯,可以說你有YourViewController創建一個新的文件名。給你的視圖一個故事板ID並選擇它的類名。

enter image description here

-(IBAction)buttonClicked:(UIButton*)okButton 
{ 
    //the view controller you want to present as popover 
    YourViewController *controller = [[YourViewController alloc] init]; 

    //if [[YourViewController alloc] init]; doesn't work try this 
    // UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard" 
                bundle:nil]; 
    //YourViewController *controller = [sb instantiateViewControllerWithIdentifier:@"YourViewController"]; 

    //our popover 
    FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller]; 

    //the popover will be presented from the okButton view 
    [popover presentPopoverFromView:okButton]; 

    //no release (ARC enable) 
    //[controller release]; 
} 

注:我還沒有使用的FPPopover之前,所以不知道如何安排的屏幕尺寸,但必須有自己的文件進一步解釋只是閱讀。

+0

非常好,謝謝。但是,如果我正在使用FPPopover庫(iPad popover的iPhone端口),它只需要popover的視圖,我可以創建一個正常的segue嗎?如果你不知道,我完全理解,我錯誤地認爲這兩者都是一樣的(大部分事情似乎是這樣)。 –

+0

@DougSmith是不是所有的東西都是一樣的ipad和iphone,所以你不能在Iphone Storyboard中創建popover segue。當你嘗試在iPhone中執行segue(push,modal)時,segue會替換當前視圖,所以它不起作用。如果你嘗試自定義segue可能是你可以實現它,但我懷疑它。所以你不能用Iphone的segue做,我會試着編輯我的答案併爲你提供一個可能的解決方案。 –

+0

@DougSmith嘗試我的iphone的答案不知道它是否會工作。 –

1

我認爲iPhone設備的更好方法是創建一個視圖控制器,其視圖的背景顏色設置爲清除。然後在這個視圖中,您只需添加一個較小尺寸的視圖,它會顯示一個彈出窗口。

呈現此視圖控制器將顯示彈出窗口的外觀。這是我採取的方法。如果用戶輕敲父視圖上小視圖範圍外的區域,則可以關閉視圖控制器。

1

iPhone的解決方案

由於iOS的8.0是可以實現這個爲iPhone應用程序呢!

目標視圖控制器(一個,它應出現在酥料餅)需要符合「UIPopoverPresentationControllerDelegate」協議,並且具有實施該消息「adaptivePresentationStyleForPresentationController:traitCollection:」。除此之外其「modalPresentationStyle」應該是「UIModalPresentationPopover」和控制器應該是他自己的「UIPopoverPresentationController」代表。

準備視圖控制器這種方式後,只需要創建一個故事板賽格瑞(型號:「存在酥料餅」)在UINavigationBarItem(或其他東西)目標視圖控制器。

enter image description here

實現:

@implementation TestViewController 

/* 
initWithCoder: 

*/ 
- (instancetype)initWithCoder:(NSCoder *)pDecoder { 
    //FLog; 

    if (self = [super initWithCoder:pDecoder]) { 

     self.modalPresentationStyle = UIModalPresentationPopover; 
     self.popoverPresentationController.delegate = self; 
    } 
    return self; 
} 


#pragma mark - POPOVER PRESENTATION CONTROLLER DELEGATE 

/* 
adaptivePresentationStyleForPresentationController:traitCollection: 

*/ 
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)pController 
                   traitCollection:(UITraitCollection *)pTraitCollection { 
    //FLog; 

    return UIModalPresentationNone; 
} 

// ... 

@end 

當然委託協議可以在其它的類也可以實現,但這種方式是最簡單的一個:-)

+0

謝謝,它只是工作! – Goppinath

相關問題