我想我的UINavigationBar在我的SignatureViewController中正確旋轉。這是目前它在旋轉時看起來如何在人像和風景模式中的示例:http://tinypic.com/view.php?pic=2w5573a&s=5#.Uk5kgYapWrg根據風景/人像更改UINavigationBar背景?
正如你所看到的,UINavigationBar在橫向上不會縮放寬度。我的項目是建立如下:
RootViewController的(UINavgationController)------ 模態推 ----->SignatureViewController
(portrait only) (portrait/landscape)
請注意,我不是使用SignatureViewController的正常推送,我使用的是模態。以防萬一我想提到這一點,因爲我不確定它是否會以任何奇怪的方式影響結果?......我嘗試了不同的方法來改變NavigationBar的背景,具體取決於它是橫向還是縱向。我會張貼一些這裏如下:
嘗試NR1:不工作
- (void) viewWillAppear:(BOOL)animated {
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"bar_nav_black.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"navbar25g.png"] forBarMetrics:UIBarMetricsLandscapePhone];
[[UINavigationBar appearance] setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
}
嘗試NR 2:不工作
- (void) viewWillAppear:(BOOL)animated {
UIImage *navBarLandscape = [[UIImage imageNamed:@"navbar25g.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(x,x,x,x)];
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"bar_nav_black.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance]setBackgroundImage:navBarLandscape forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
}
嘗試NR3:不工作
- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
{
UIView *v = [[UIView alloc]init];
int a = [[notification.userInfo objectForKey: UIApplicationStatusBarOrientationUserInfoKey] intValue];
int w = [[UIScreen mainScreen] bounds].size.width;
int h = [[UIScreen mainScreen] bounds].size.height;
switch(a){
case 4:
v.frame = CGRectMake(0,20,w,h);
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"bar_nav_black.png"] forBarMetrics:UIBarMetricsDefault];//Have also tried with UIBarMetricsLandscapePhone...
NSLog(@"willrotate:1");
break;
case 3:
v.frame = CGRectMake(-20,0,w-20,h+20);
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"navbar25g.png"] forBarMetrics:UIBarMetricsDefault];//Have also tried with UIBarMetricsLandscapePhone...
NSLog(@"willrotate:2");
[self.view addSubview:v];
break;
case 2:
v.frame = CGRectMake(0,-20,w,h);
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"bar_nav_black.png"] forBarMetrics:UIBarMetricsDefault];//Have also tried with UIBarMetricsLandscapePhone...
NSLog(@"willrotate:3");
break;
case 1:
v.frame = CGRectMake(20,0,w-20,h+20);
NSLog(@"willrotate:4");
[[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"navbar25g.png"] forBarMetrics:UIBarMetricsDefault];//Have also tried with UIBarMetricsLandscapePhone...
}
請注意,在嘗試nr3 NSLog工作,但它拒絕更改UINavigationBar的背景。那麼,我想從這裏做什麼想法? /問候
對不起,延遲迴復,但我沒有工作:( – user1293618