사용자가 화면을 처음로드 할 때 스크롤보기가 자동으로 스크롤되기를 원하므로이 코드를 사용하고 있습니다.
[UIView animateWithDuration:(float)1.25f
animations:^{
myScrollView.contentOffset = CGPointMake(2000, 800);
}
completion:nil];
따라서 코드는 훌륭하게 작동하고 UIScrollView는 내가 원하는 CGPoint로 "스크롤"(애니메이션)을 시뮬레이션하지만 사용자가 수동으로 손가락을 대고 스크롤을 시작하거나 중지하려는 경우 스크롤하는 동안 사용자는 할 수 없습니다. 완료 될 때까지이 애니메이션을 재정의합니다.
누구든지 재정의 기능으로 애니메이션을 만드는 더 나은 방법에 대한 아이디어를 가지고 있으며, 재정의 기능을 언제 호출 해야하는지 (나는 이것이 scrollView의 뷰에서 touchesBegan을 포함한다고 가정하고 있습니다)
UIViewAnimationOptionAllowUserInteraction
애니메이션 옵션에 추가 하기 만하면 됩니다.
[UIView animateWithDuration:1.25f delay:0.0f options:(UIViewAnimationOptionAllowUserInteraction) animations:^{
_scrollView.contentOffset = CGPointMake(0, 800);
}
completion:nil];
UIScrollView scrollViewWillBeginDragging:
대리자 메서드 에서 애니메이션을 취소합니다.
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
//Storing current offset
CALayer *currentLayer = _scrollView.layer.presentationLayer;
CGPoint scrollBoundsOrigin = currentLayer.bounds.origin;
//Cancelling animations
[_scrollView.layer removeAllAnimations];
//Restore offset
_scrollView.contentOffset = scrollBoundsOrigin;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다