iPad方向问题
我从一个有 2 个视图(firstviewcontroller 和 secondaryviewcontroller)的选项卡栏应用程序开始。第二个视图控制器没有背景图像,但第一个视图控制器有。
我有两张图片,一张是肖像,一张是风景。我想做的就是每当方向改变时加载背景图像。我想支持所有方向。
这是我的 viewdidload 方法
-(void)viewDidLoad
{
imgview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgportrait.png"]];
[imgview setFrame:CGRectMake(0, 0, 768, 1024)];
[self.view addSubview:imgview];
[self.view sendSubviewToBack:imgview];
[imgview release];
}
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { NSLog(@"应该旋转"); 返回是; 在willRotateToInterfaceOrientation
(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == (UIInterfaceOrientationPortrait || UIInterfaceOrientationPortraitUpsideDown))
{
NSLog(@"in portrait");
}
else if (toInterfaceOrientation == (UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight))
{
NSLog(@"in landscape");
}
}
中,它永远不会进入任何 if 循环,并且不会打印日志,我不确定为什么它的方向与它们中的任何一个都不匹配。我只想为第一个视图控制器设置适当的背景图像。我知道它应该很简单,但我无法做到正确。
I started off with an tabbar application which has 2 views(firstviewcontroller and secondviewcontroller).the second view controller does not have a background image but the first one does.
i have 2 images one for protrait and one for landscape. all i want to do is load an background image whenever the orientation is changed. i want to support all orientations.
here is my viewdidload method
-(void)viewDidLoad
{
imgview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgportrait.png"]];
[imgview setFrame:CGRectMake(0, 0, 768, 1024)];
[self.view addSubview:imgview];
[self.view sendSubviewToBack:imgview];
[imgview release];
}
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{ NSLog(@"in shouldrotate");
return YES;
}
(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == (UIInterfaceOrientationPortrait || UIInterfaceOrientationPortraitUpsideDown))
{
NSLog(@"in portrait");
}
else if (toInterfaceOrientation == (UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight))
{
NSLog(@"in landscape");
}
}
in the willRotateToInterfaceOrientation it never goes into any of the if loop and it doesnt print the log, i am not sure why its not matching the orientation to either of them. i just want to set the appropriate backgroundimage to the firstviewcontroller. i know it should be very simple but i am not able to get it right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样检查你的状况
check your condition like this