9
A
回答
7
賦予了新的信息 - 沒有UINavigationController的 - 事情是不同的。下面是我的代碼中的相關位...
創建導航欄,並將其添加到您的視圖:
// Create the navigation bar
self.navBar = [[UINavigationBar alloc] init];
[self.view addSubview:self.navBar];
萊出來..
- (CGRect)frameForOrientation:(UIInterfaceOrientation)theOrientation
{
UIScreen *screen = [UIScreen mainScreen];
CGRect fullScreenRect = screen.bounds; // always implicitly in Portrait orientation.
CGRect appFrame = screen.applicationFrame;
// Find status bar height by checking which dimension of the applicationFrame is narrower than screen bounds.
// Little bit ugly looking, but it'll still work even if they change the status bar height in future.
float statusBarHeight = MAX((fullScreenRect.size.width - appFrame.size.width), (fullScreenRect.size.height - appFrame.size.height));
// Initially assume portrait orientation.
float width = fullScreenRect.size.width;
float height = fullScreenRect.size.height;
// Correct for orientation.
if (UIInterfaceOrientationIsLandscape(theOrientation)) {
width = fullScreenRect.size.height;
height = fullScreenRect.size.width;
}
// Account for status bar, which always subtracts from the height (since it's always at the top of the screen).
height -= statusBarHeight;
return CGRectMake(0, statusBarHeight, width, height);
}
- (CGSize)viewSizeForOrientation:(UIInterfaceOrientation)theOrientation
{
CGRect frame = [self frameForOrientation:theOrientation];
return CGSizeMake(frame.size.width, frame.size.height);
}
- (void)layoutSubviewsForInterfaceOrientation:(UIInterfaceOrientation)theOrientation withAnimation:(BOOL)animate
{
CGSize fullSize = [self viewSizeForOrientation:theOrientation];
float width = fullSize.width;
float height = fullSize.height;
CGRect newFrame = CGRectMake(0, 0, width, height);
SubViewController *controller;
UIView *theView;
// Place the navigation bar
CGRect navBarFrame = newFrame;
navBarFrame.size.height = NAVBARHEIGHT;
self.navBar.frame = navBarFrame;
}
創建一個函數誰它/隱藏:
- (void)showNavigationBar:(BOOL)show
{
if (show == YES && self.navBar.hidden == YES) {
// Move the frame out of sight
CGRect frame = self.navBar.frame;
frame.origin.y = -frame.size.height;
self.navBar.frame = frame;
// Display it nicely
self.navBar.hidden = NO;
frame.origin.y = 0.0;
[self.view bringSubviewToFront:self.navBar];
[UIView animateWithDuration:0.3
animations:^(void) {
self.navBar.frame = frame;
}
];
}
else if (show == NO && self.navBar.hidden == NO) {
CGRect frame = self.navBar.frame;
// Display it nicely
frame.origin.y = -frame.size.height;
[self.view bringSubviewToFront:self.navBar];
[UIView animateWithDuration:0.3
animations:^(void) {
self.navBar.frame = frame;
}
completion:^(BOOL finished) {
self.navBar.hidden = YES;
}
];
}
}
其中
#define NAVBARHEIGHT 44
11
前視圖顯示:
[self.navigationController setToolbarHidden:YES];
當你按下按鈕:
[self.navigationController setToolbarHidden:NO];
+0
我已經把工具欄放在視圖控制器中,而不是在導航控制器中。有沒有辦法使事情工作,或我應該使用導航cotroller? –
+0
看到我的其他答案 – tarmes
1
下面是一些tarmes的代碼移植到MonoTouch/c#。
public static RectangleF FrameForOrientation(UIInterfaceOrientation orientation) {
var screen = UIScreen.MainScreen;
var fullScreenRect = screen.Bounds; // always implicitly in Portrait orientation.
var appFrame = screen.ApplicationFrame;
// Find status bar height by checking which dimension of the applicationFrame is narrower than screen bounds.
// Little bit ugly looking, but it'll still work even if they change the status bar height in future.
var statusBarHeight = Math.Max((fullScreenRect.Width - appFrame.Width), (fullScreenRect.Height- appFrame.Height));
// Initially assume portrait orientation.
var width = fullScreenRect.Width;
var height = fullScreenRect.Height;
// Correct for orientation.
if (IsLandscapeOrientation(orientation)) {
width = fullScreenRect.Height;
height = fullScreenRect.Width;
}
// Account for status bar, which always subtracts from the height (since it's always at the top of the screen).
height -= statusBarHeight;
return new RectangleF(0, statusBarHeight, width, height);
}
public static SizeF SizeForOrientation(UIInterfaceOrientation orientation) {
var frame = FrameForOrientation(orientation);
return new SizeF(frame.Width, frame.Height);
}
public static bool IsLandscapeOrientation(UIInterfaceOrientation orientation) {
return
orientation == UIInterfaceOrientation.LandscapeLeft ||
orientation == UIInterfaceOrientation.LandscapeRight;
}
相關問題
- 1. iPhone:隱藏工具欄
- 2. 隱藏並顯示ckeditor工具欄
- 3. 如何顯示/隱藏PhotoSwipe工具欄
- 4. 隱藏工具欄
- 5. 隱藏工具欄
- 6. 同時隱藏/顯示導航欄,工具欄和狀態欄
- 7. 如何隱藏工具欄?
- 8. 如何隱藏工具欄
- 9. HTML5 - 隱藏工具欄
- 10. 輕觸隱藏工具欄
- 11. 隱藏SSRS工具欄
- 12. 隱藏工具欄Jquery Mobile
- 13. 使工具欄隱藏
- 14. SVG工具提示隱藏/顯示
- 15. TinyMCE:按需顯示和隱藏內聯工具欄
- 16. 隱藏/顯示水龍頭上的工具欄
- 17. Android的工具欄顯示/隱藏空白
- 18. Ckeditor:根據需要顯示和隱藏內聯工具欄
- 19. 隱藏和顯示kendo ui編輯器工具欄
- 20. 工具欄不隱藏/顯示在滾動協調器佈局
- 21. 如何顯示Eclipse的隱藏工具欄
- 22. 以編程方式在CoordinatorLayout上隱藏/顯示工具欄
- 23. iOS 7 - 隱藏tabBar並顯示工具欄,而不是
- 24. CoordinatorLayout:隱藏/顯示半可見工具欄?
- 25. Compact Framework的底部工具欄上顯示/隱藏
- 26. 安卓:隱藏/顯示工具欄,而滾動不起作用
- 27. 顯示/隱藏工具欄的ActionButton? Firefox SDK for addon
- 28. 如何使用sencha touch顯示和隱藏分頁工具欄?
- 29. 如何隱藏tabbar時顯示工具欄?
- 30. 在eclipse中隱藏顯示視圖工具欄
'[self.navigationController setToolbarHidden:YES];' – Kjuly
的UIView有一個屬性[隱藏](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/ UIView.html#// apple_ref/occ/instp/UIView/hidden) – beryllium
我不確定爲什麼這個問題被投票爲-1。我投票回來了,因爲我試着沒有NavigationController同樣的事情(儘管應該在問題中提到) –