在我的类(class)中,我编写了以下委托(delegate)方法:
scrollViewDidScroll:
scrollViewDidEndScrollingAnimation:
然后对于这个 scrollView
我使用下面的代码:
scrollView.frame = ...;
scrollView.contentSize = ...;
[scrollView setContentOffset:... animated:NO];
代码和委托(delegate)在主线程中工作,但彼此异步。
问题是我不想用这段代码调用描述的委托(delegate)方法。如何解决这个问题?我不能简单地写:
BOOL shouldCallDelegate = YES; //or NO
因为我还有其他代码需要通过这些委托(delegate)方法处理。
已更新
我试过这样的:
NSLog(@"isMainThread == %d", [NSThread isMainThread]);
NSLog(@"isScrollViewBusy == %d", self.isScrollViewBusy);
self.isScrollViewBusy = YES;
scrollView.frame = ...;
scrollView.contentSize = ...;
[scrollView setContentOffset:... animated:NO];
self.isScrollViewBusy = NO;
然后在我的委托(delegate)方法中:
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
NSLog(@"isMainThread2 == %d", [NSThread isMainThread]);
NSLog(@"isScrollViewBusy2 == %d", self.isScrollViewBusy);
...
}
你认为应用程序必须写这样的东西吗?
isMainThread == 1
isScrollViewBusy == 0
isMainThread2 == 1
isScrollViewBusy2 == 0
在大多数情况下是这样,但是当您尝试旋转屏幕时:
isMainThread == 1
isScrollViewBusy == 0
isMainThread2 == 1
isScrollViewBusy2 == 1
所以所有代码都在主线程中,但突然间代码的第一部分暂停?!当应用程序正在处理旋转并且委托(delegate)方法被意外调用时介于 YES 和 NO 之间
最佳答案
id<UIScrollViewDelegate> delegate = scrollView.delegate;
scrollView.delegate = nil;
// do your stuff
scrollView.delegate = delegate
关于ios - 以编程方式滚动 UIScrollView 但不仅仅在委托(delegate)方法中处理此操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28899309/