您的位置:首页 > 产品设计 > UI/UE

UIScrollView(滑动视图)

2016-01-12 22:46 411 查看
//设置一个scrollview给他大小(容器)
    UIScrollView *myscroll=[[UIScrollView alloc]initWithFrame:self.view.frame];
    myscroll.backgroundColor=[UIColor blackColor];
    
    UIImage *img=[UIImage imageNamed:@"zhuomian.jpg"];
    UIImageView *v1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,
img.size.width, img.size.width)];
    v1.image=img;
    //水平滚动显示器
//    myscroll.showsHorizontalScrollIndicator=NO;
    //垂直滚动显示器
//    myscroll.showsVerticalScrollIndicator=NO;
    [myscroll addSubview:v1];
    //设置scrovie内容大小,内容高宽大于容器高宽,可以滑动,相等或者小于就不能滑动
    myscroll.contentSize=CGSizeMake(img.size.width,
img.size.height);
    [self.view addSubview:myscroll];
    //回弹速率
    myscroll.decelerationRate=0.2;
    //指示器的样式
    myscroll.indicatorStyle=UIScrollViewIndicatorStyleWhite;
    //设置conten边距
    myscroll.contentInset=UIEdgeInsetsMake(60, 0, 0, 0);
    //设置显示器边距
//    myscroll.scrollIndicatorInsets=UIEdgeInsetsMake(100, 100, 100, 100);
    //闪现
    [myscroll flashScrollIndicators];
    //是否定向锁
    myscroll.directionalLockEnabled=NO;
    //是否启用分页
    myscroll.pagingEnabled=YES;
    //是否回弹
    myscroll.bounces=NO;
    //是否启用滚动
    myscroll.scrollEnabled=YES;
    
    myscroll.delegate=self;
    myscroll.minimumZoomScale=1.0;
    myscroll.maximumZoomScale=1.5;
    
    
}
//代理方法&l
4000
t;
UICollectionViewDelegate
>

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"滑动已经开始了");
    scrollView.contentOffset;//拿到偏移量
    scrollView.contentOffset;//在x轴上的偏移量
    NSLog(@"pagepage%f",(int)scrollView.contentOffset.x/self.view.frame.size.width);
    
}// any offset changes
- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2){
    NSLog(@"已经开始缩放了");
}// any zoom scale changes

// called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    NSLog(@"将要开始拖动");
}
// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0){
    NSLog(@"hahah%@ gggg%f  hhh%f",scrollView,velocity.x,targetContentOffset->x);
}
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    NSLog(@"已经结束拖拽 %d",decelerate);
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    NSLog(@"开始减速");
}// called on finger up as we are moving
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;{
    NSLog(@"已经结束减速");
}// called when scroll view grinds to a halt

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
    NSLog(@"滑动的动画停止");
    
}// called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating

- (nullable UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return self.view;
}// return a view that will be scaled. if delegate returns nil, nothing happens
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view NS_AVAILABLE_IOS(3_2){
    NSLog(@"将要开始zoming");
}
// called before the scroll view begins zooming its content
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view
atScale:(CGFloat)scale{
    NSLog(@"已经结束zoming");
}
// scale between minimum and maximum. called after any 'bounce' animations

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{
    return YES;
}
// return a yes if you want to scroll to the top. if not defined, assumes YES
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{
    NSLog(@"已经回到顶部");
}
// called when scrolling animation finished. may be called immediately if already at top
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: