uiscrollview의 맨 아래에있는 uibittons는 터치를받지 않습니다.

StackOverflow https://stackoverflow.com/questions/1401369

  •  05-07-2019
  •  | 
  •  

문제

탭 바와 내비게이션 바가있는 iPhone 앱을 작성하고 있습니다. 어느 시점에서 세부 사항 ViewController 클래스의 인스턴스를 탐색 컨트롤러 스택으로 푸시하여 표시합니다.

이 컨트롤러는 코드에서 View Hierarchy를 만듭니다 : The Controller 's view 속성은 UiscrollView로 설정되어 있으며, 여기에는 일반적인 uiview ( "ContentView") 크기가 포함되어 있습니다. 이 ContentView의 맨 아래에는 4 개의 uiatton이 있습니다.

이제 앱을 실행하고 (현재 시뮬레이터에서) 뷰 하단으로 스크롤하면 상단 두 버튼이 터치에 응답합니다. 세 번째는 맨 위 부분에서만 터치에 응답하며 하단 버튼은 터치에 전혀 응답하지 않습니다. 세 번째 버튼의 여러 부분을 클릭하면 스크롤보기의 93 픽셀이 터치 이벤트를 하위 뷰로 전달하지 않는 것으로 보입니다.

93은 의심 스럽다 : 또한 그것은 또한 탭 막대 (49 픽셀)와 내비게이션 바 (44 픽셀)의 결합 된 높이이기도합니다. 그러나 탐색 막대와 탭 막대는 스크롤보기 외부에 있습니다. 왜 이런 일이 일어날 지 제안이 있습니까?

문제의 코드는 다음과 같습니다.

- (void)loadView
{
    CGRect frame = [[UIScreen mainScreen] applicationFrame]; 
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame];
    scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    scrollView.delegate = self;
    self.view = scrollView;

    UIView *contentView = [[UIView alloc] initWithFrame:scrollView.bounds];
    contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    [scrollView addSubview:contentView];

    CGSize viewSize = contentView.bounds.size;
    CGSize size;
    CGFloat y = 0;

    /* Snip creating various labels and image views */

    /* Actions view creates and lays out the four buttons; its sizeThatFits:
    ** method returns the frame size to contain the buttons */

    actionsView = [[PropertyDetailActionsView alloc] initWithFrame:CGRectZero];
    actionsView.autoresizingMask = (UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth);
    actionsView.delegate = self;
    size = [actionsView sizeThatFits:viewSize];
    actionsView.frame = CGRectMake(0, y, size.width, size.height);
    [contentView addSubview:actionsView];
    y += size.height;

    [contentView setFrame:CGRectMake(0, 0, viewSize.width, y)];
    scrollView.contentSize = contentView.frame.size;

    [contentView release];
    [scrollView release];
}
도움이 되었습니까?

해결책

어제 트위터에서 제안했듯이 유연한 바닥 여백이 ActionView로 설정된 것과 관련이있을 수 있습니다.

그 제안은 문제를 해결하지 못했지만 올바른 방향으로 이어집니다. 컨텐츠 뷰의 유연한 높이를 제거하면 문제가 해결되었습니다.

따라서 누군가가 비슷한 문제를 겪고 있다면 자동화하는 마스크를 가지고 놀아보십시오.

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