开发者

UIScrollView content offset blocks user interaction

开发者 https://www.devze.com 2023-04-12 00:32 出处:网络
I\'m making an app what contains a scroll view with some subviews what are built up on UIGestures...

I'm making an app what contains a scroll view with some subviews what are built up on UIGestures...

The idea is to be able to use it in both orientations, in portrait.. it would be full screen but in landscape the user would have to scroll to access all the content however I have had some issues trying to get it to work correctly.

Here is how I have my view laid out:

UIView -> UIScrollView -> UIView -> UIImageView -> Subviews with Gesture recognisers.

the first UIView is just the UIViewControllers View, the UIScrollView is what will/should handle the difference in orientation, the second UIView is just a container to stop positioning screwing up and the UIImageView holds my image what is a diagram where I have placed a series of custom checkboxes and labels into/over the UIImageView to display content and receive and handle interaction...

In Portrait, this will work flawlessly however when I rotate to landscape, the content inside the UIScrollView is shifted up by 128pixels so the top is inaccessible... this also makes the bottom 128pixels too big so there is a transparent gap..

I can fix this by running this code on the didRotateFromInterfaceOrientation: function:

int offset = 0;
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) 
    offset = 128;
else 
    offset = 0;
[scrollView setContentInset:UIEdgeInsetsMake(offset, 0, -offset, 0)];

The code above just alters the ContentIns开发者_Python百科et's top and bottom property to adjust the postion by 128 pixels each way... the scroll view will then display the content fine...

However, when I attempt to touch any of the gestures within 128pixels from the bottom, they will not work! I've tried so much to get it working but also if i don't alter the contentInset they will still not work (within 128 from the bottom)... It's really confusing me as I have userInteractionEnabled set to YES on all of my views but it still wont work, anything else will and content is displayed fine within this 128pixels area...

Does anybody know what is wrong with this or have anything I can try as I feel that I have tried everything possible.

Thanks for reading,

Liam


I figured it out in the end... It was an issue with the frame size changing... all I had to do was run this code on the didRotate function:

int offset = 0;
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
    [scrollView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    offset = 128;
} else { 
    [scrollView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    offset = 0;
}
[scrollView setContentInset:UIEdgeInsetsMake(offset, 0, -offset, 0)];

It just makes sure that the frame is reset back to the size of the view once rotated... I figure it was an issue with autoresize masks but I didn't have the time to play around with them and this works just as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消