我正在尝试创建 UINavigationBar 的自定义外观。当用户将应用置于横向时,navigationBar 应该被一个 Image 覆盖。当旋转回纵向时,我希望删除视图(图像)。除了删除它之外,下面的代码一切正常。如果我将代码放在同一个 if 语句中,我可以删除视图,但如果我把它放在 else if 语句中,则不会发生任何事情。我错过了什么吗?/ 问候
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
UIView *v = [[UIView alloc]init];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
v.frame = CGRectMake(0,0,480,44);
v.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"navbar25g.png"]];
[self.view addSubview:v];
//[v removeFromSuperview]; <----- works if I put it here
NSLog(@"LANDSCAPE");//load the landscape view
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[v removeFromSuperview]; <----- Not working
NSLog(@"PORTRAIT"); //load the portrait view
}
}