UIScrollerView基础

来源:互联网 发布:剑三成男25号脸数据 编辑:程序博客网 时间:2024/04/25 21:17

#import "ViewController.h"


@interface ViewController ()

{

   UIImageView *image;

   UIScrollView *scrollerView;

}


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

   scrollerView = [[UIScrollViewalloc]init];

    scrollerView.frame =self.view.frame;

    [self.viewaddSubview:scrollerView];

    

    image = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, 1600,1607)];

   image.image = [UIImageimageNamed:@"IMG_2780"];

    [scrollerView addSubview:image];

    

    //设置滚动范围

   scrollerView.contentSize =CGSizeMake(1600,1067);

    //设置间距

   scrollerView.contentInset =UIEdgeInsetsMake(50,50, 50, 50);

    //设置初始偏移量

   scrollerView.contentOffset =CGPointMake(100,100);

    

    //隐藏水平滚动条

    scrollerView.showsHorizontalScrollIndicator =NO;

    //隐藏垂直滚动条

    scrollerView.showsVerticalScrollIndicator =NO;

    //弹簧效果

    scrollerView.bounces =NO;

    //是否允许与用户交互

    scrollerView.userInteractionEnabled =YES;

    

    UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    btn.frame = CGRectMake(self.view.frame.size.width / 2, self.view.frame.size.height /2, 50,50);

    [btn setTitle:@"滚动"forState:UIControlStateNormal];

    [btn addTarget:selfaction:@selector(move)forControlEvents:UIControlEventTouchUpInside];

    btn.titleLabel.textColor = [UIColorblackColor];

    btn.titleLabel.font = [UIFontsystemFontOfSize:18];

    [self.viewaddSubview:btn];

}  


- (void)move{

    

    CGPoint offSet =scrollerView.contentOffset;

    offSet.x +=50;

//    scrollerView.contentOffset = offSet;

    [UIViewanimateWithDuration:1animations:^{

        scrollerView.contentOffset = offSet;

    }];

}



1 0
原创粉丝点击