简体   繁体   English

使用Storyboard和Autolayout旋转到横向后,UIScrollView中的UIButton是否不可触摸?

[英]UIButtons in UIScrollView is not touchable after rotate to landscape orientation using Storyboard and Autolayout?

I have a lot of "Buttons" in a View in a ScrollView , in a SuperView , of the ViewController . 我在ViewControllerScrollViewSuperViewView中有很多“按钮”。

ViewController
   View
      ScrollView
         View
            Button
            Button
            Button
            Button
            Button
            ....

I use autolayout , View to ScrollView (trailing, top, bot, lead 0, align x,y center) same for ScrollView to ViewController.View . 我使用autolayout ,将视图设置为ScrollView (跟踪,顶部,机器人,前导0,对齐x,y中心),将ScrollViewViewController.View

when rotate to landscape mode, the screen only recognizes touches from x 0 to 320 , any button after x 320 is not touchable. 当旋转到横向模式,屏幕仅识别触摸从X 0至320,任何按钮后×320不是可触摸。

I did change the frame of the SuperView , ScrollView and Content View but did not do anything 我确实更改了SuperViewScrollView和Content View的框架,但没有做任何事情

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        _contentView.frame = CGRectMake(0, 0, 1000,1000);
        _mainView.frame = CGRectMake(0, 0, 1000,1000);
        _scrollView.frame = CGRectMake(0, 0, 1000,1000);

        NSLog(@"size of self is %@",NSStringFromCGSize(self.view.frame.size));
        NSLog(@"size of scrollview is %@",NSStringFromCGSize(_scrollView.frame.size));
        NSLog(@"size of contentView is %@",NSStringFromCGSize(_contentView.frame.size));
        NSLog(@"size of MainView is %@",NSStringFromCGSize(_mainView.frame.size));

    } else {
    }
}

Does anyone know why? 有人知道为什么吗?

Thanks. 谢谢。

As Matt suggested, I change the frame after the rotation ( didRotateFromInterfaceOrientation ). 正如Matt所建议的,我在旋转后更改了框架( didRotateFromInterfaceOrientation )。 Here are the log of the frames of the views and one button not touchable 这是视图框架的日志和一个不可触摸的按钮

2014-04-29 18:08:27.528 [84526:60b] size of self is {{0, 0}, {568, 288}}
2014-04-29 18:08:27.529 [84526:60b] size of scroolview is {{0, 0}, {568, 336}}
2014-04-29 18:08:27.529 [84526:60b] size of content is {568, 466}
2014-04-29 18:08:27.529 [84526:60b] size of contentView is {{0, 0}, {568, 466}}
2014-04-29 18:08:27.530 [84526:60b] size of MainView is {{0, 0}, {568, 288}}
2014-04-29 18:08:27.530 [84526:60b] size of myBtn is {{364, 45}, {50, 50}}

So myBtn is inside the contentView yet it's not touchable? 所以myBtn在contentView内,但是还是不可触摸的?

Do you get any constraint warning when you rotate the device? 旋转设备时会收到任何约束警告吗?

I had the same issue, was able to see a pickerview but were not tappable when I rotate the device. 我遇到了同样的问题,能够看到pickerview,但是旋转设备时却无法点击。 after return to the previous orientation worked again. 回到以前的方向后,再次工作。

In my case the solution was to remove all constraints (backup project first) and reset to suggested constraints. 在我的情况下,解决方案是删除所有约束(首先备份项目)并重置为建议的约束。

Then It worked. 然后它起作用了。

Hope it helps. 希望能帮助到你。

As interesting info: I'll tell you this started to happen, after I update XCode from 4.X to 5.0, so, probably something in the storyboard was not upgraded correctly. 作为有趣的信息:我将XCode从4.X更新到5.0之后,这将开始发生,因此,情节提要中的某些内容可能未正确升级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM