#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)];
[self.view addSubview:self.scrollVC];
self.scrollVC.delegate = self;
self.scrollVC.backgroundColor = [UIColor orangeColor];
self.scrollVC.contentSize = CGSizeMake(400, 400);
self.scrollVC.clipsToBounds = YES;
self.scrollVC.scrollEnabled = YES;
self.scrollVC.userInteractionEnabled = 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];
}
#pragma mark - UIScrollViewDelegate 协议
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"UIScrollViewDelegate 协议");
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(@"即将开始拖拽");
}
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
NSLog(@"用户即将停止拖拽");
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if(decelerate == NO){
NSLog(@"用户已经停止拖拽,停止滚动");
}else{
NSLog(@"用户已经停止拖拽,滚但是由于惯性 会继续滚动 并且减速");
}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(@"减速完毕 停止滚动");
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return self.imageView;
}
@end