//聲明 UIScrollView-》#27932A
#952775 #602AAB
@property (nonatomic,strong)
UIScrollView *scrollview;
//聲明 UIImageView
@property (nonatomic,strong) UIImageView *imageview;
//初始化 UIScrollView
self.scrollview = [[UIScrollView alloc] init];
//設置 frame
self.scrollview.frame =
self.imageview.bounds;
//設置背景色
self.scrollview.backgroundColor = [UIColor blueColor];
//設置滾動範圍
self.scrollview.contentSize = CGSizeMake(
self.imageview.image.size.width,
self.imageview.image.size.height);
//設置滾動的位置
self.scrollview.contentOffset = CGPointMake(0,0);
//設置內邊距
self.scrollview.contentInset = UIEdgeInsetsMake(0,0, 80, 100)
;
//設置是否有彈簧效果
self.scrollview.bounces =
YES;
//默認no,控制垂直方向遇到邊框是否反彈(但bounces爲NO時,它爲yes,也不反彈)
self.scrollview.alwaysBounceVertical =
YES;
//默認no,控制水平方向遇到邊框是否反彈(但bounces爲NO時,它爲yes,也不反彈)
self.scrollview.alwaysBounceHorizontal =
YES;
//是否容許滾動到頂部
self.scrollview.scrollsToTop =
YES;
//設置是否分頁
self.scrollview.pagingEnabled =
NO;
//設置是否容許拖動
self.scrollview.scrollEnabled =
YES;
//設置是否顯示水平滾動條
self.scrollview.showsHorizontalScrollIndicator =
YES;
//設置是否顯示垂直滾動條
self.scrollview.showsVerticalScrollIndicator =
YES;
//設置滾動條的位置
self.scrollview.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,0,0);
//設置滾動條的樣式
self.scrollview.indicatorStyle = UIScrollViewIndicatorStyleDefault;
//設置 代理
self.scrollview.delegate =
self;
//設置最大/最小縮放比
self.scrollview.maximumZoomScale = 1.0;
self.scrollview.minimumZoomScale = 3.5;
[
self.view addSubview:
self.scrollview];
[
self.scrollview addSubview:
self.imageview];
CGFloat Y =
self.scrollview.contentOffset.y + 5;
CGFloat X =
self.scrollview.contentOffset.x + 5;
//設置滾動的位置
[
self.scrollview setContentOffset:CGPointMake(X, Y) animated:
YES];
//遵照代議 :UIScrollViewDelegate
#pragma mark - Delegate
//正在滾動
- (
void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(
@"正在滾動...
");
}
//即將開始滾動。
-(
void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(
@"即將開始滾動...
");
}
//完成滾動(鬆手後調用)
-(
void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
NSLog(
@"完成滾動...
");
}
//開始減速滾動(完成滾動 調用)
-(
void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
NSLog(
@"開始減速滾動...
");
}
//結束減速滾動 (滾動結束調用)
-(
void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
NSLog(
@"結束減速滾動...
");
}
//滾動到頂部
-(
BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{
NSLog(
@"滾動到頂部...
");
return YES;
}
//滾動到頂部調用(scrollsToTop 設置爲YES時點擊狀態欄調用)
-(
void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{
NSLog(
@"滾動到頂部調用...
");
}
//設置縮放的對象
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return
self.imageview;
}
//即將開始縮放
-(
void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{
NSLog(
@"即將開始縮放...
");
}
//正在縮放
-(
void)scrollViewDidZoom:(UIScrollView *)scrollView{
NSLog(
@"正在縮放...
");
}