UIScrollView

#import "AppScrollVC.h"

@interface AppScrollVC ()<UIScrollViewDelegate>

@property(nonatomic,strong) UIScrollView *scrollVC;
@property(nonatomic,strong) UIImageView *imageView;

@end

@implementation AppScrollVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    self.scrollVC = [[UIScrollView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-100, self.view.frame.size.height/2-100, 200, 200)];
     
    //将 scrollVC 添加到 view本页面中
    [self.view addSubview:self.scrollVC];
    
    //设置代理 遵守协议
    self.scrollVC.delegate = self;
    
    //背景色
    self.scrollVC.backgroundColor = [UIColor orangeColor];
    
    //可滚动的面积范围  contentSize必须大于控件尺寸才可滚动;
    self.scrollVC.contentSize = CGSizeMake(400, 400);
    
    //超出边框是否可显示  默认YES;
    self.scrollVC.clipsToBounds = YES;
    
    //控制是否能滚动;
    self.scrollVC.scrollEnabled = YES;
    
    //是否能与用户交互 是否响应用户操作 任何控件都有这个属性;
    self.scrollVC.userInteractionEnabled = YES;
    
    //设置弹簧效果 默认YES
    self.scrollVC.bounces = YES;
    
    //竖直水平有回弹效果(下拉刷新 上拉加载)
    self.scrollVC.alwaysBounceHorizontal = YES;
    self.scrollVC.alwaysBounceVertical = NO;
    
    //是否显示滚动条
    self.scrollVC.showsHorizontalScrollIndicator = YES;
    self.scrollVC.showsVerticalScrollIndicator = YES;
    
    //控制内容的偏移量/滚动的位置
    self.scrollVC.contentOffset=CGPointMake(0, 0);
    
    //控制内容滑动后的内边距
    self.scrollVC.contentInset = UIEdgeInsetsMake(20, 20, 20, 20);
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(self.scrollVC.frame.size.width/2-50, self.scrollVC.frame.size.height/2-50, 100, 100)];
    lable.backgroundColor = [UIColor yellowColor];
    [self.scrollVC addSubview:lable];

/*
       self.imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1"]];
    self.scrollVC = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    self.scrollVC.contentSize = CGSizeMake(self.imageView.frame.size.width, self.imageView.frame.size.height);
    [self.view addSubview:self.scrollVC];
    [self.scrollVC addSubview:self.imageView];
    //缩放限制
    self.scrollVC.maximumZoomScale = 10.0;
    self.scrollVC.minimumZoomScale = 0.5;
 */
    
}


/* UIScrollViewDelegate 协议方法 */
#pragma mark - UIScrollViewDelegate 协议

// ScrollView 正在滚动的时候自动调用
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"UIScrollViewDelegate 协议");
}

// ScrollView 即将开始拖拽的时候调用
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    NSLog(@"即将开始拖拽");
}

// ScrollView 用户即将停止拖拽
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    NSLog(@"用户即将停止拖拽");
}

// ScrollView 用户已经停止拖拽
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if(decelerate == NO){
        NSLog(@"用户已经停止拖拽,停止滚动");
    }else{
        NSLog(@"用户已经停止拖拽,滚但是由于惯性 会继续滚动 并且减速");
    }
}

// ScrollView 减速完毕 停止滚动
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    NSLog(@"减速完毕 停止滚动");
}

//缩放事件
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return self.imageView;
}
@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值