目标 c 中 didload 方法启动时的 LandscapeOrientation

发布于 2024-12-25 15:53:50 字数 463 浏览 0 评论 0原文

我制作了一个 iPad 应用程序,

当我第一次以纵向模式加载应用程序时,它工作正常,但是当我第一次以横向模式加载应用程序时,它仅采用纵向模式的坐标,因为在我的 < code>didLoad 方法我只给出纵向模式的坐标。

现在需要在我的 didLoad 方法中给出横向模式的坐标。

我在 didLoad 方法中尝试了此操作,

if (interfaceOrientation == UIInterfacePortraitmode ||
    interfaceOrientation == UIInterfaceUpsideDown)
{
    // do this....
}
else
{
    // do this....
}

但无法在 didLoad 方法中编写 if/else 的条件。

我应该怎么办?

I've made an iPad application,

It works fine when I load my application in portrait mode for first time, but when I load my application in landscape mode for the first time, it takes the coordinates of portrait mode only, because inside my didLoad method I give coordinates of portrait mode only.

Now need to give coordinates of landscape mode inside my didLoad method.

I tried this, inside my didLoad method

if (interfaceOrientation == UIInterfacePortraitmode ||
    interfaceOrientation == UIInterfaceUpsideDown)
{
    // do this....
}
else
{
    // do this....
}

but I am unable to write the condition for the if/else inside my didLoad method.

What should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

煮茶煮酒煮时光 2025-01-01 15:53:50

您可以按如下方式进行处理 -

-(void) viewWillAppear: (BOOL) animated {
       [super viewWillAppear: animated];
       [self updateLayoutForNewOrientation: self.interfaceOrientation];
}

-(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration {
       [self updateLayoutForNewOrientation: interfaceOrientation];
}

最后是自定义方法 -

- (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation {
    if (UIInterfaceOrientationIsLandscape(orientation)) {
         // Do some stuff
    } else {
         // Do some other stuff
    }

}

You can do handling as below -

-(void) viewWillAppear: (BOOL) animated {
       [super viewWillAppear: animated];
       [self updateLayoutForNewOrientation: self.interfaceOrientation];
}

-(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration {
       [self updateLayoutForNewOrientation: interfaceOrientation];
}

and then finally custom method -

- (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation {
    if (UIInterfaceOrientationIsLandscape(orientation)) {
         // Do some stuff
    } else {
         // Do some other stuff
    }

}

爱的故事 2025-01-01 15:53:50
-(void) viewWillAppear: (BOOL) animated {
       [super viewWillAppear: animated];
       [self adjustViewtForNewOrientation: self.interfaceOrientation];
}

-(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration {
       [self adjustViewtForNewOrientation: interfaceOrientation];
}


- (void) adjustViewtForNewOrientation: (UIInterfaceOrientation) orientation {
    if (UIInterfaceOrientationIsLandscape(orientation)) {
         // Do some stuff
    } else {
         // Do some other stuff
    }

还可以在 ViewDidLaod() 方法中调用 adjustViewtForNewOrientation ,

-(void) viewWillAppear: (BOOL) animated {
       [super viewWillAppear: animated];
       [self adjustViewtForNewOrientation: self.interfaceOrientation];
}

-(void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation duration: (NSTimeInterval) duration {
       [self adjustViewtForNewOrientation: interfaceOrientation];
}


- (void) adjustViewtForNewOrientation: (UIInterfaceOrientation) orientation {
    if (UIInterfaceOrientationIsLandscape(orientation)) {
         // Do some stuff
    } else {
         // Do some other stuff
    }

also call adjustViewtForNewOrientation in your ViewDidLaod() method,

多情癖 2025-01-01 15:53:50

我对 UIScrollView 也有类似的问题。我通过按照此处的建议对齐子视图来修复它。

- (void)alignSubViews
{
    // Position all the content views at their respective page positions
    scrollView.contentSize = CGSizeMake(self.contentViews.count * scrollView.bounds.size.width,
                                        scrollView.bounds.size.height);
    NSUInteger i = 0;
    for (UIView *v in self.contentViews) {
        v.frame = CGRectMake(i * scrollView.bounds.size.width, 0,
                             scrollView.bounds.size.width, scrollView.bounds.size.height);
        i++;
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Setup subviews and then align the views.

    [self alignSubViews];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
                                         duration:(NSTimeInterval)duration 
{
    [self alignSubViews];
    scrollView.contentOffset = CGPointMake(self.currentPage * scrollView.bounds.size.width, 0);
}

I had similar issue with UIScrollView. I had it fixed by aligning the subviews as suggested here.

- (void)alignSubViews
{
    // Position all the content views at their respective page positions
    scrollView.contentSize = CGSizeMake(self.contentViews.count * scrollView.bounds.size.width,
                                        scrollView.bounds.size.height);
    NSUInteger i = 0;
    for (UIView *v in self.contentViews) {
        v.frame = CGRectMake(i * scrollView.bounds.size.width, 0,
                             scrollView.bounds.size.width, scrollView.bounds.size.height);
        i++;
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Setup subviews and then align the views.

    [self alignSubViews];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
                                         duration:(NSTimeInterval)duration 
{
    [self alignSubViews];
    scrollView.contentOffset = CGPointMake(self.currentPage * scrollView.bounds.size.width, 0);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文