uiview가 보이고 화면에 있는지 어떻게 알 수 있습니까?
-
02-07-2019 - |
문제
내가있는 경우 UIView
(또는 UIView
서브 클래스) 보이는 경우, 현재 화면에 표시되는지 (예 : 현재 화면이 아닌 스크롤보기의 섹션에있는 것과 반대로) 어떻게 알 수 있습니까?
내가 의미하는 바에 대한 더 나은 아이디어를 줄 수도 있습니다. UITableView
현재 보이는 세포의 세트를 결정하는 몇 가지 방법이 있습니다. 나는 주어진 것에 대해 비슷한 결정을 내릴 수있는 코드를 찾고 있습니다. UIView
.
해결책
아직 시도하지 않았습니다. 하지만 CGRectIntersectsRect()
, -[UIView convertRect:to(from)View]
그리고 -[UIScrollView contentOffset]
여기에서 기본 빌딩 블록 인 것 같습니다.
다른 팁
UiscrollView에서 어떤 uiviews가 보이는지 확인하는 데 사용한 내용은 다음과 같습니다.
for(UIView* view in scrollView.subviews) {
if([view isKindOfClass:[SomeView class]]) {
// the parent of view of scrollView (which basically matches the application frame)
CGRect f = self.view.frame;
// adjust our frame to match the scroll view's content offset
f.origin.y = _scrollView.contentOffset.y;
CGRect r = [self.view convertRect:view.frame toView:self.view];
if(CGRectIntersectsRect(f, r)) {
// view is visible
}
}
}
최근에 내보기가 화면인지 확인해야했습니다. 이것은 나를 위해 효과가있었습니다.
CGRect viewFrame = self.view.frame;
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
// We may have received messages while this tableview is offscreen
if (CGRectIntersectsRect(viewFrame, appFrame)) {
// Do work here
}
if you are primarily worried about releasing an object that is not in the view hierarchy, you could test to see if it has a superview, as in:
if (myView.superview){
//do something with myView because you can assume it is on the screen
}
else {
//myView is not in the view hierarchy
}
제휴하지 않습니다 StackOverflow