문제

Is there a way to create a custom view with vertical or horizontal scrolling but not both? When in portrait mode, vertical scrolling should be enabled and horizontal scrolling should be disabled When in landscape mode, horizontal scrolling is enabled and vertical scrolling is disabled.

도움이 되었습니까?

해결책

You can set the contentSize property of your UIScrollView depending on which orientation you are going to turn to.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation) {
        [self.scrollView setContentSize:CGSizeMake(self.scrollView.bounds.size.width, scrollViewContentHeight)];
    } else {
        [self.scrollView setContentSize:CGSizeMake(scrollViewContentWidth, self.scrollView.bounds.size.height)];
    }
}

다른 팁

This all depends on your UIScrollView's content size. If the content size overflows the scrollView's frame's height - you'll enable horizontal scrolling. If it exceeds the height, you'll enable vertical scrolling.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top