是否有任何方式來調整已使用故事板segue模態呈現的視圖控制器的大小?ios5 - 模型視圖控制器的大小與故事板
如何通過翻轉過渡從此模態視圖控制器中呈現另一個視圖控制器?
如果我將其定義爲Style = Modal,Presentation = Default,Transition = Flip Horizontal,它看起來很奇怪(背景是白色的)。
Thx!
是否有任何方式來調整已使用故事板segue模態呈現的視圖控制器的大小?ios5 - 模型視圖控制器的大小與故事板
如何通過翻轉過渡從此模態視圖控制器中呈現另一個視圖控制器?
如果我將其定義爲Style = Modal,Presentation = Default,Transition = Flip Horizontal,它看起來很奇怪(背景是白色的)。
Thx!
我試圖做同樣的,在故事板我ModalView較小,但在模擬器它涵蓋了所有的屏幕...
我覺得這不能在iPhone上完成了...(我在iPad上做了一個簡單的測試,模態視圖起作用)。
我會嘗試iPhone的半透明視圖,不會使用模態視圖。
希望這會有所幫助。
您可以使用自定義UIStoryboardSegue調整模態顯示視圖的大小。在故事板中,將segue設置爲Custom而不是Modal。在Segue類中,給它一個你的UIStoryboardSegue覆蓋的名字。
要覆蓋UIStoryboardSegue,您在.h文件中不需要任何東西。它會出現這樣的事情:
MyStoryboardSegue.h:
#import <UIKit/UIKit.h>
@interface MyStoryboardSegue : UIStoryboardSegue
@end
在MyStoryboardSegue.m,代碼爲:
#import "MyStoryboardSegue.h"
@implementation MyStoryboardSegue
- (void)perform
{
id sourceController = self.sourceViewController;
id destinationController = self.destinationViewController;
UIView *destinationView = [destinationController view];
CGFloat x, y, w, h;
[destinationController setModalPresentationStyle:UIModalPresentationFormSheet];
[destinationController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[sourceController presentViewController:destinationController animated:YES completion:nil];
/*
You have to present the view first, and then resize it. That's because,
as far as I can tell, when you present your view modally, a new view is created
that covers the screen in a black semi-transparent mask to give the shadow effect,
and a container view is placed in the middle of this view that in turn holds the
view you are presenting. Your view automatically resizes to the size of this
container view, so that's the view you need to resize to make your view controller
appear the size you desire. You must present your modal view first
because until you do, the container view doesn't exist. The following code
resizes the container view (which is now your modal view's superview) and then
resets the position of the container view to the center of the source view that
is presenting the modal view so everything looks nice and centered.
*/
x = destinationView.superview.frame.origin.x;
y = destinationView.superview.frame.origin.y;
w = 400; // Your desired modal view width
h = 400; // Your desired modal view height
destinationView.superview.frame = CGRectMake(x, y, w, h);
destinationView.superview.center = [[sourceController view] center];
}
@end
我已經在UINavigationController中的Xcode 5中完成了這項工作(如果有的話),它似乎不工作,除非我失去了一些東西...... –
注意,你幾乎總是需要一個modalViewController拿整個屏幕。這是因爲在modalViewController出現後,「在」modalViewController下的viewController被移除。因此,如果你試圖用你的modalViewController覆蓋屏幕的一半,其目的是讓其他viewController顯示「underneath」,這是行不通的。它會顯示白色。我通過添加視圖作爲父視圖的子視圖來完成此功能。 – bearMountain
您的評論在框架行爲方面可能是正確的,但是您的「想要」應該由您的應用的用戶體驗決定,以及對用戶最合適,而不是UI框架的底層交互。您的用戶體驗可能決定在自定義對話框中顯示您的模態UI,在這種情況下,您仍然需要查看對話框後面的內容。通過根據需要手動添加/刪除對話框子視圖(變暗,對話框內容),自定義的漸變和展開漸變可輕鬆處理此操作,而無需刪除先前控制器的視圖。 – Marchy
http:// stackoverflow上有一個工作解決方案。com/questions/25250510/set-size-of-iphone-view-controller/25251507#25251507 –