2012-10-04 2 views
0

UIScrollView에서 뷰에 대한 터치에 응답하려고합니다. UIScrollView를 서브 클래 싱하여 표준 서브 뷰로 전달 된 표준 감각을 얻을 수 있었지만, 뷰를 누른 상태에서 스크롤 한 다음 놓아두면 "touchesEnded"메서드가 호출되지 않으므로 뷰가 강조 표시됩니다.iOS : UIScroll보기 -보기 터치에서 스크롤을 방지합니다.

이 문제를 해결하고 싶습니다.

는 내가보기를 탭하면 스크롤을 방지하기 위해이 가이드를 따라하려고 시도했습니다 :

http://www.musicalgeometry.com/?p=1404

한 단계는 뷰의 프레임에 CGRect 속성을 설정하는 작업이 포함됩니다. 이 작업을 시도하면 내 하위보기의 프레임이 (0, 0, 0, 0)이라고 표시됩니다. 이것은 -viewDidLoad에 있으므로보기가 그때까지로드되어 있어야합니다.

-viewDidLoad : 여기

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [scrollView setScrollEnabled:YES]; 
    [scrollView setDelaysContentTouches:NO]; 

    //Here I attempt to get the frame of my subview, but it gives me 
    //(0,0,0,0) 
    scrollView.subViewRect=locPhoneView.frame; 

    locImageView.image=locImage; 
    locNameLabel.text=locName; 
    locAddressLabel.text=locAddress; 
    locPhoneLabel.text=locPhone; 
    monHoursLabel.text=[NSString stringWithFormat:@"Mon:  %@",[locHours objectAtIndex:0]]; 
    tueHoursLabel.text=[NSString stringWithFormat:@"Tue:  %@",[locHours objectAtIndex:1]]; 
    wedHoursLabel.text=[NSString stringWithFormat:@"Wed:  %@",[locHours objectAtIndex:2]]; 
    thuHoursLabel.text=[NSString stringWithFormat:@"Thu:  %@",[locHours objectAtIndex:3]]; 
    friHoursLabel.text=[NSString stringWithFormat:@"Fri:  %@",[locHours objectAtIndex:4]]; 
    satHoursLabel.text=[NSString stringWithFormat:@"Sat:  %@",[locHours objectAtIndex:5]]; 
    sunHoursLabel.text=[NSString stringWithFormat:@"Sun:  %@",[locHours objectAtIndex:6]]; 
    closedSundayLabel.text=[locHours objectAtIndex:7]; 
} 

내 "터치"방법이 있습니다.

  1. 는 어떻게받을 수 있나요 locPhoneView.frame 나에게 정확한 치수를주고 :

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
        UITouch *touch = [touches anyObject]; 
        if(touch.view==locPhoneView){ 
         locPhoneView.backgroundColor=[ColorUtility colorWithHexString:@"83d3f0"]; 
        } 
        if(touch.view==locAddressView){ 
         locAddressView.backgroundColor=[ColorUtility colorWithHexString:@"83d3f0"]; 
        } 
    } 
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 
        UITouch *touch = [touches anyObject]; 
        if(touch.view==locPhoneView){ 
         locPhoneView.backgroundColor=[UIColor whiteColor]; 
        } 
        if(touch.view==locAddressView){ 
         locAddressView.backgroundColor=[UIColor whiteColor]; 
        } 
    
    } 
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ 
    
    } 
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
    
    } 
    

    그래서 나는 두 가지 답을 찾고있는 것 같아?

  2. 터치의 시작과 끝 사이에 스크롤이 있어도 "touchesEnded"메서드가 호출되도록하는 방법이 있습니까? 또는 scrollViewDidEndDragging : 또는 scrollViewDidEndDecelerating가 : 당신이 도움이 될

답변

0

내가 정확히 질문하지만 scrollViewDidScroll 같이있는 ScrollView 대표 생겼는지 모르겠습니다. Responding to Scrolling and Dragging을 참조하십시오.

기본적으로 스크롤 뷰 내부의 터치를 처리하려면 터치를 자신의보기 컨트롤러 인 다음 응답자로 리디렉션해야합니다.

+0

예, 성공적으로 다음 응답자에게 전달했습니다. 그러나보기를 터치 한 다음 스크롤 한 다음 놓으면 올바르게 작동하지 않습니다. 이 경우 "touchesEnded"는 호출되지 않습니다. 나는이 문제를 해결할 방법을 찾고있다. 위의 링크에서 제안 된 솔루션을 찾았지만 locPhoneView.frame에 대한 올바른 값을 얻지 못하고 있습니다. –

+0

정확히 그렇다면 scrollViewdidScroll 또는 scrollview 대리자 메서드 중 하나를 사용해야합니다. 뷰를 터치 할 때 isTouchBegun을 나타내는 플래그를 설정하고 scrollview 대리자 메서드에서이 플래그가 설정되어 있으면 뷰의 뷰를 터치 한 다음 스크롤하여이 뷰의 endTouch 이벤트를 가져와야합니다. 희망은 그 말이 맞습니다. – applefreak

+0

훌륭한 작품입니다. 감사! –

관련 문제