在UIScrollView中进行分页是一个很棒的功能,我需要的是将分页设置为较小的距离,例如我希望我的UIScrollView页面的大小小于UIScrollView的帧宽.谢谢
我似乎无法调用scrollViewDidEndDecelerating.我有一个带有2个视图的scrollView.现在我需要它在滚动视图完成滚动到第二个视图时在第一个视图中为标签设置一个值.
头文件:
@interface ViewController: UIViewController
{
UIScrollView *scrollView;
UIView *view1;
UIView *view2;
}
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIView *view1;
@property (strong, nonatomic) IBOutlet UIView *view2;
@property (weak, nonatomic) IBOutlet UILabel *lbl;
Run Code Online (Sandbox Code Playgroud)
实施档案:
@synthesize scrollView, view1, view2;
-(void)viewDidLoad
{
self.view1=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.view2=[[UIView alloc] initWithFrame:CGRectMake(320, 0, 320, 480)];
[self.scrollView addSubView:self.view1];
[self.scrollView addSubView:self.view2];
self.scrollView.bounces=NO;
self.scrollView.contentSize=CGSizeMake(640,460);
[self.scrollView setShowHorizontalScrollIndicator:NO];
[self.scrollView scrollRectToVisible:CGRectMake(0, 0, 320, 416) animated:NO];
}
-(void)scrollViewDidEndDecelerating:(UIView *)scrollView
{
lbl.text=@"0";
}
Run Code Online (Sandbox Code Playgroud)
我没有看到任何错误,它应该工作.有人可以帮我吗?会很感激.
我正在尝试实现滚动视图,在滚动时捕捉到点.
我看到的所有帖子都是关于在用户结束拖动滚动后'捕捉到一个点'.我想在拖动过程中使其快速捕捉.
到目前为止,我有这个拖动后停止惯性,它工作正常:
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
targetContentOffset.memory = scrollView.contentOffset
}
Run Code Online (Sandbox Code Playgroud)
我尝试了这个,但没有按照预期工作:
var scrollSnapHeight : CGFloat = myScrollView.contentSize.height/10
Run Code Online (Sandbox Code Playgroud)
scrollViewDidScroll:
func scrollViewDidScroll(scrollView: UIScrollView) {
let remainder : CGFloat = scrollView.contentOffset.y % scrollSnapHeight
var scrollPoint : CGPoint = scrollView.contentOffset
if remainder != 0 && scrollView.dragging
{
if self.lastOffset > scrollView.contentOffset.y //Scrolling Down
{
scrollPoint.y += (scrollSnapHeight - remainder)
NSLog("scrollDown")
}
else //Scrolling Up
{
scrollPoint.y -= (scrollSnapHeight - remainder)
}
scrollView .setContentOffset(scrollPoint, animated: …Run Code Online (Sandbox Code Playgroud)