2010-01-27 1 views
0

종이에 위치와 오프셋을 계산했습니다. 필자는 코드를 작성하고 예상 된 결과를 얻을 수 있도록 디버깅했습니다. 그러나 iPhone 시뮬레이터의 경우는 약 15 픽셀만큼이 겹칩니다.iPhone 시뮬레이터 화면에서 UI 개체의 위치를 ​​측정하는 방법

내 디버깅을 계속하려면 정확히 UI 개체가 화면에 어디에 있는지 알아야합니다.

팝업 검색과 관련하여 정적 UISearchBar와 동적으로 추가 된 UITabBar (테이블보기가 탭 중 하나에 포함됨) 사이에서 UITableView를 키보드 및 크기 조정하는 것과 관련이 있습니다. 아니요, 실제로 하드 코딩 된 값을 사용하지 않으려 고 로테이션 및 다른 화면 크기가 필요합니다.

어떻게 알 수 있습니까?

- (void)keyboardWasShown:(NSNotification*)aNotification 
{ 
if (self.keyboardShown) 
    return; 

// Get keyboard dimensions 
NSDictionary* info = [aNotification userInfo]; 
NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey]; 
CGSize kbSize = [aValue CGRectValue].size; 
NSValue* endValue = [info objectForKey:UIKeyboardCenterEndUserInfoKey]; 
CGPoint endCenter = [endValue CGPointValue]; 

CGRect frame = myView.frame; 
frame.size.height = endCenter.y - kbSize.height/2 - frame.origin.y; 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.2]; 

myView.frame = frame; 

[UIView commitAnimations]; 

self.keyboardShown = YES; 
} 

... 난 더 이상 볼 수없는 명백한 버그가있어 단지의 경우 코드 ...

+0

죄송합니다, 발견 대답 : http://gargantuchet.blogspot.com/2009/12/i-came-across-post-updating -uiview-to.html하지만 시뮬레이터 화면에서 UI 객체의 정확한 위치를 알 수있는 방법을 알고 싶습니다. – JOM

답변

1

가장 좋은 방법은 아마도 UIView의의 convertPoint:toView:입니다. 주어진보기의 위치, 찾으려면 사용

CGPoint myPoint = [myView convertPoint:CGPointMake(0, 0) toView:((YourAppDelegate *)[[UIApplication sharedApplication] delegate]).window]; 
코드 부분
+0

위대한 팁, 내가 찾고 있던 것보다 훨씬 낫다! – JOM