Tra*_*sen 7 iphone objective-c uiscrollview ios
我在UIScrollView中有一系列图像.当用户释放滚动动作时,我希望视图以单个图像为中心.我已实现代码,但基础行为不正确.我对setContentOffset:animated:的调用具有正确的值,但视图实际上并未滚动到该点.这是一些调试的输出:
2011-03-26 17:28:16.201 PivotMachine[39984:207] Dragging Beginning at: 270, 0
2011-03-26 17:28:16.322 PivotMachine[39984:207] Dragging Ended at: 360, 0 --> 350, 0
2011-03-26 17:28:16.624 PivotMachine[39984:207] Scrolling Ended at: 350, 0
2011-03-26 17:28:25.648 PivotMachine[39984:207] Dragging Beginning at: 447, 0
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,在内部,它认为它在360处停止拖动,因此适当地提升到350,应该在那里.在视觉上,它坐在450左右,它知道什么时候我再次开始拖动(是的,我知道你没有立即开始,所以我拖得很慢,只能在活动前移动几个像素).
这是拖动代码(对于我的UIScrollView子类):
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
CGPoint myLocation = self.contentOffset;
NSLog(@"Dragging Beginning at: %3.0f, %3.0f", myLocation.x, myLocation.y);
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollV
{
CGPoint myLocation = self.contentOffset;
NSLog(@" Scrolling Ended at: %3.0f, %3.0f", myLocation.x, myLocation.y);
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
// Auto-scroll to the center of the closest menu
if (scrollView != self)
{
DLog(@"[ScrollMenu scrollViewWillBeginDecelerating] called with non-self");
return;
}
CGPoint myLocation = self.contentOffset;
int idx = [self indexOfMenuClosestTo:myLocation];
CGPoint menuPoint = CGPointMake(menuPoints[idx], self.contentOffset.y);
NSLog(@" Dragging Ended at: %3.0f, %3.0f --> %3.0f, %3.0f",
myLocation.x, myLocation.y, menuPoint.x, menuPoint.y);
[self setContentOffset:menuPoint animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我应该注意到这是在模拟器中.我还不能在实际的手机上试试,因为我还没有在开发程序上花钱(等到我的应用程序几乎准备好发布以防万一我用完了).
这可能是一个模拟器问题吗?有没有人见过类似的东西?哦,是的,我应该问:我做错了什么?;)
跟进:我认为问题是减速动画与我的-(void) setContentOffset:animated:通话冲突.两个动画都继续运行,视图显示哪个获胜,但内部状态正确基于setContentOffset.我以为setContentOffset关闭了现有的动画.是的,如果没有,我怎么能把它关掉?