我知道还有其他问题,但现在已经过时且未针对iOS 7更新。我遇到的问题是设置目标内容偏移量并不仅适用于特定的{{1条件。滚动视图不会滚动到我设置的targetContentOffset,它只是正常滚动和减速。我基本上尝试使用自定义宽度页面重新创建分页功能。此滚动视图已添加到UITableViewCell,并且已禁用“自动布局”。
以下是我设置滚动视图的方法:
if
这些是我的委托方法:
UIScrollView *myScrollView = [[UIScrollView alloc] init];
myScrollView.frame = CGRectMake(0, 0, 320, 85);;
myScrollView.contentSize = CGSizeMake(776, 85);
myScrollView.pagingEnabled = NO;
myScrollView.scrollEnabled = YES;
myScrollView.showsHorizontalScrollIndicator = NO;
myScrollView.delegate = self;
myScrollView.contentOffset = CGPointMake(228, 0);
myScrollView.decelerationRate = UIScrollViewDecelerationRateFast;
我每次拖动只获得一个-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
lastCellOffset = scrollView.contentOffset.x;
//Sets the offset the scrollview is scrolling from
}
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if (scrollView != self.tableView) {
if (velocity.x > 0.0 || velocity.x == 0.0) { //If scrolling or dragging left i.e. going to the right
if (lastCellOffset == 0.0) { //If dragged from first page
*targetContentOffset = CGPointMake(228.0, 0); //Set content offset to second page
lastCellOffset = 228.0; //Not completely necessary I think
NSLog(@"Left - to page 1");
} else if (lastCellOffset == 228.0) { //If dragged from second page
*targetContentOffset = CGPointMake(548.0, 0); //Scroll to second page NOT WORKING IF X > 228.0
lastCellOffset = 548.0;
NSLog(@"Left - to page 2"); //Called!
}
}
if (velocity.x < 0.0 || velocity.x == 0.0) {
if (lastCellOffset == 228.0) {
*targetContentOffset = CGPointMake(0.0, 0.0);
lastCellOffset = 0.0;
NSLog(@"Top1");
} else if (lastCellOffset == 548.0) {
*targetContentOffset = CGPointMake(228.0, 0.0);
lastCellOffset = 228.0;
NSLog(@"Bottom1");
}
}
}
}
,所以我知道它不会以某种方式取消自身或重置到不同的位置,只调用我想调用的条件。
修改:如果我将NSLog
设置为小于content offset.x
的任何内容,它是否有效?