iPad方向问题

发布于 2024-10-08 16:29:24 字数 1195 浏览 2 评论 0原文

我从一个有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你另情深 2024-10-15 16:29:24

像这样检查你的状况

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation==UIInterfaceOrientationPortrait || 
       toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
    {
       NSLog(@"in portrait");
    }
    else
    {
        NSLog(@"in landscape");
    }
}

check your condition like this

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation==UIInterfaceOrientationPortrait || 
       toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
    {
       NSLog(@"in portrait");
    }
    else
    {
        NSLog(@"in landscape");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文