-
[iOS] scrollViewDidEndScrollingAnimation이 시뮬레이터에서는 호출되지만 디바이스에서 호출되지 않을 때프로그래밍/iOS 2021. 3. 24. 23:23
문제 상황
테이블뷰에서 마지막 셀로 스크롤시켰을때, 스크롤 애니메이션이 끝날때 호출되는 메서드인 scrollViewDidEndScrollingAnimation에 마지막 셀에 접근하고 키보드 팝업을 올리려고 했다.
tableView.scrollToRow를 사용했을 때 시뮬레이터에서는 scrollViewDidEndScrollingAnimation가 호출이 되었지만, 디바이스에서는 호출이 안되었다.
원인
scrollViewDidEndScrollingAnimation은 setContentOffset:animated:또는 scrollRectToVisible:animated:을 사용할 때만 호출된다고 한다.
scrollToRow를 사용했을 때 시뮬레이터에서는 호출되었던건 왜 그런지 모르겠음.
해결방법
tableView.scrollToRow를 setContentOffset:animated으로 대신 구현했다.
나의 경우는 마지막 셀로 이동해야 하는 상황이다.
let indexPath = IndexPath(row: 0, section: self.todoList.count - 1) self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
위 코드를 아래와 같이 바꿔주었다.
let bottomOffset = CGPoint(x: 0, y: tableView.contentSize.height - tableView.frame.size.height) tableView.setContentOffset(bottomOffset, animated: true)
출처
stackoverflow.com/a/16403675/14854771
scrollViewDidEndScrollingAnimation not getting called
I want to perform some action when scrollview finish scrolling, so I wrote that acton in scrollViewDidEndScrollingAnimation delegate method. It is working fine when rect is not visible and scrollview
stackoverflow.com
scrollView scrollRectToVisible working on simulator and not working on device
EDIT: i tried this code in a new project and it works as expected. the following code is used on top of a opengl view (using cocos2d) added with [[[CCDirector sharedDirector]openGLView]addSubv...
stackoverflow.com
반응형'프로그래밍 > iOS' 카테고리의 다른 글
NSCoding 쓸 때 does not implement methodSignatureForSelector: 에러가 나는 경우 (0) 2021.09.17 [iOS] navigation bar의 large title를 쓸 때 반투명으로 바꾸는 방법 (0) 2021.08.25 [iOS] hidesSearchBarWhenScrolling가 작동하지 않을 때 (0) 2021.03.13 [iOS] tableView.indexPath(for: UITableViewCell)이 nil이 반환될 때 (0) 2021.03.09 [iOS] IBDesignable 사용시 에러 기록 (0) 2021.02.23