프로그래밍/iOS

[iOS] scrollViewDidEndScrollingAnimation이 시뮬레이터에서는 호출되지만 디바이스에서 호출되지 않을 때

turu 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

stackoverflow.com/questions/5958515/scrollview-scrollrecttovisible-working-on-simulator-and-not-working-on-device/66782904#66782904

 

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

 

반응형