我正在尝试创建自定义外观的UINavigationBar。当用户将应用放在横向位置时,navigationBar应该用一个Image覆盖。当旋转回肖像时,我想要删除视图(图像)。除了删除它之外,一切工作都正常。如果我将代码放在相同的if语句中,我可以删除View,但如果将其放入else if语句中,则不会发生任何反应。我错过了什么吗? /关注将子视图添加到UINavigationBar并将其删除
- (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
}
}