0

정말이 사건에 대해 일주일 만에 막혔습니다. 난 UINavigationItem 내부 UIBarButtonItem이 계층 구조는 BarButtonItem가 segmentedControl의 래퍼이touchesBegan 및 touchesEnded가 다른 하위보기에서 감지되었습니다.

alt text

같다. UIBarbuttonitem 및 UIsegmentedControl은 프로그래밍 방식으로 만들어 지지만 다른 것은 IB로 만들어집니다.

이 경우 barbuttonitem을 누르거나 터치 한 다음보기를 표시하고 싶습니다. 이 포럼에서 읽은 여러 스레드에서 나는 UIBarbuttonItem이 UIResponder를 상속받지 않는다는 것을 알고 있었기 때문에 NavigationBar를 선택하여 터치를 얻었고 프레임을 정의했습니다.

이 난 이루어지는 코드 :

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
navBar = self.navigationController.navigationBar; 
int index = _docSegmentedControl.selectedSegmentIndex; 
NSLog(@"index di touches began : %d", index); 
CGFloat x; 

if (index == 0) { 
    x = 0.0; 
}else if (index == 1) { 
     x = widthSegment + 1; 
}else if (index == 2) { 
     x = 2*widthSegment + 1; 
}else if (index == 3) { 
     x = 3*widthSegment+ 1; 
}else if (in dex == 4) { 
     x = 4*widthSegment + 1; 
} 

CGRect frame = CGRectMake(x, 0.00, widthSegment, 46.00); 

UITouch *touch = [touches anyObject]; 
CGPoint gestureStartPoint = [touch locationInView:navBar]; 

NSLog(@"gesturestart : %f, %f", gestureStartPoint.x, gestureStartPoint.y); 

if (CGRectContainsPoint(frame, gestureStartPoint)) { 
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(segmentItemTapped:) object:[self navBar]]; 
    NSLog(@"cancel popover"); 
} 
} 

네비게이션 바는 myViewController.h에서 선언 였고 제가 함께 IBOutlet로 설정. 내가 아닌 메뉴 바에서 툴바로 누를 때

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ 
int index = _docSegmentedControl.selectedSegmentIndex; 
NSLog(@"index di touches ended : %d", index); 
navBar = self.navigationController.navigationBar; 
CGFloat x; 

if (index == 0) { 
     x = 0.0; 
}else if (index == 1) { 
     x = widthSegment + 1; 
}else if (in dex == 2) { 
     x = 2*widthSegment + 1; 
}else if (index == 3) { 
     x = 3*widthSegment+ 1; 
}else if (index == 4) { 
     x = 4*widthSegment + 1; 
} 

CGRect frame = CGRectMake(x, 0.00, widthSegment, 46.00); 

UITouch *touch = [touches anyObject]; 
CGPoint gestureLastPoint = [touch locationInView:navBar]; 

NSLog(@"lastPOint : %d", gestureLastPoint); 

if (CGRectContainsPoint(frame, gestureLastPoint)) { 
    if (touch.tapCount <= 2) { 
      [self performSelector:@selector(segmentItemTapped:) withObject:nil afterDelay:0.0]; 
    } 
} 
} 

는 touchesBegan 및 touchesEnded 검출 하였다.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { 
    UIView *touchedView = [super hitTest:point withEvent:event]; 
    NSSet* touches = [event allTouches]; 
    // handle touches if you need 
    return touchedView; 
} 

을하지만 여전히 아무것도 더 나은 얻을 :

나는이 같은 그러나 hitTest 방법을 구현했다.

누군가 이런 일이 일어난 이유를 누가 설명 할 수 있습니까? 감사
-Risma- 당신은 단순히 당신의 도움의 아지에 대한

[self.mybarbutton setAction:@selector(barButtonTapped:)]; 

[self.mybarbutton setTarget:self]; 

답변

0

에서, segmentItemTap 동작이에 대한 작업입니다

popover를 보여줘. 내가 코드를 쓰자. popover가 오지 않았다. 발견되지 않은 터치에 대해 생각했다 .Began and touches 내 navbar에서 끝냈다, 왜 그런지 알고 있니?
+0

들으처럼 barbutton 항목에 작업을 추가 할 수 있지만 내 문제를 해결할 수없는 –

관련 문제