// 觸摸屏幕來滾動(dòng)畫面還是其他的方法使得畫面滾動(dòng),皆觸發(fā)該函數(shù)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"Scrolling...");
}
創(chuàng)新互聯(lián)為企業(yè)提供:成都品牌網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷策劃、小程序設(shè)計(jì)、營(yíng)銷型網(wǎng)站建設(shè)和網(wǎng)站運(yùn)營(yíng)托管,一站式網(wǎng)絡(luò)營(yíng)銷整體服務(wù)。實(shí)現(xiàn)不斷獲取潛在客戶之核心目標(biāo),建立了企業(yè)專屬的“營(yíng)銷型網(wǎng)站”,就用不著再為了獲取潛在客戶而苦惱,相反,客戶會(huì)主動(dòng)找您,生意就找上門來了!
// 觸摸屏幕并拖拽畫面,再松開,最后停止時(shí),觸發(fā)該函數(shù)
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"scrollViewDidEndDragging - End of Scrolling.");
}
// 滾動(dòng)停止時(shí),觸發(fā)該函數(shù)
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidEndDecelerating - End of Scrolling.");
}
// 調(diào)用以下函數(shù),來自動(dòng)滾動(dòng)到想要的位置,此過程中設(shè)置有動(dòng)畫效果,停止時(shí),觸發(fā)該函數(shù)
// UIScrollView的setContentOffset:animated:
// UIScrollView的scrollRectToVisible:animated:
// UITableView的scrollToRowAtIndexPath:atScrollPosition:animated:
// UITableView的selectRowAtIndexPath:animated:scrollPosition:
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidEndScrollingAnimation - End of Scrolling.");
}
首先實(shí)現(xiàn)UIScrollViewDelegate協(xié)議:
[plain] view plaincopy
#import
@interface Activity01ViewController : UIViewController
UIScrollView *myscrollview;
}
@property (nonatomic,retain) UIScrollView *myscrollview;
@end
對(duì)myscrollview進(jìn)行初始化:
[plain] view plaincopy
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
myscrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 44,768, 1004)];
myscrollview.directionalLockEnabled = YES; //只能一個(gè)方向滑動(dòng)
myscrollview.pagingEnabled = NO; //是否翻頁(yè)
myscrollview.backgroundColor = [UIColor blackColor];
myscrollview.showsVerticalScrollIndicator =YES; //垂直方向的滾動(dòng)指示
myscrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滾動(dòng)指示的風(fēng)格
myscrollview.showsHorizontalScrollIndicator = NO;//水平方向的滾動(dòng)指示
myscrollview.delegate = self;
CGSize newSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+1);
[myscrollview setContentSize:newSize];
float x=0;
float y=0;
float width =768;
float height = 1004;
UIImageView *myp_w_picpath = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"Activity01.png"]];
//[myp_w_picpath setContentMode:UIViewContentModeScaleAspectFill];
[myp_w_picpath setFrame:CGRectMake(x, y, width, height)];
[myscrollview addSubview:myp_w_picpath];
[self.view addSubview:myscrollview];
}
屬性總結(jié):
屬性 作用
CGPoint contentOffSet 監(jiān)控目前滾動(dòng)的位置
CGSize contentSize 滾動(dòng)范圍的大小
UIEdgeInsets contentInset 視圖在scrollView中的位置
id
BOOL directionalLockEnabled 指定控件是否只能在一個(gè)方向上滾動(dòng)
BOOL bounces 控制控件遇到邊框是否反彈
BOOL alwaysBounceVertical 控制垂直方向遇到邊框是否反彈
BOOL alwaysBounceHorizontal 控制水平方向遇到邊框是否反彈
BOOL pagingEnabled 控制控件是否整頁(yè)翻動(dòng)
BOOL scrollEnabled 控制控件是否能滾動(dòng)
BOOL showsHorizontalScrollIndicator 控制是否顯示水平方向的滾動(dòng)條
BOOL showsVerticalScrollIndicator 控制是否顯示垂直方向的滾動(dòng)條
UIEdgeInsets scrollIndicatorInsets 指定滾動(dòng)條在scrollerView中的位置
UIScrollViewIndicatorStyleindicatorStyle 設(shè)定滾動(dòng)條的樣式
float decelerationRate 改變scrollerView的減速點(diǎn)位置
BOOL tracking 監(jiān)控當(dāng)前目標(biāo)是否正在被跟蹤
BOOL dragging 監(jiān)控當(dāng)前目標(biāo)是否正在被拖拽
BOOL decelerating 監(jiān)控當(dāng)前目標(biāo)是否正在減速
BOOL delaysContentTouches 控制視圖是否延時(shí)調(diào)用開始滾動(dòng)的方法
BOOL canCancelContentTouches 控制控件是否接觸取消touch的事件
float minimumZoomScale 縮小的最小比例
float maximumZoomScale 放大的最大比例
float zoomScale 設(shè)置變化比例
BOOL bouncesZoom 控制縮放的時(shí)候是否會(huì)反彈
BOOL zooming 判斷控件的大小是否正在改變
BOOL zoomBouncing 判斷是否正在進(jìn)行縮放反彈
BOOL scrollsToTop 控制控件滾動(dòng)到頂部
注意:
1、使scrollview不要上下滑動(dòng),可以設(shè)置
scrollview.contentSize = CGSizeMake(你要的長(zhǎng)度, 0);
協(xié)議方法解釋:
[plain] view plaincopy
#pragma mark UIScrollViewDelegate
//只要滾動(dòng)了就會(huì)觸發(fā)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
{
// NSLog(@" scrollViewDidScroll");
NSLog(@"ContentOffset x is %f,yis %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
}
//開始拖拽視圖
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewWillBeginDragging");
}
//完成拖拽
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
{
NSLog(@"scrollViewDidEndDragging");
}
//將開始降速時(shí)
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewWillBeginDecelerating");
}
//減速停止了時(shí)執(zhí)行,手觸摸時(shí)執(zhí)行執(zhí)行
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidEndDecelerating");
}
//滾動(dòng)動(dòng)畫停止時(shí)執(zhí)行,代碼改變時(shí)出發(fā),也就是setContentOffset改變時(shí)
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidEndScrollingAnimation");
}
//設(shè)置放大縮小的視圖,要是uiscrollview的subview
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
{
NSLog(@"viewForZoomingInScrollView");
return viewA;
}
//完成放大縮小時(shí)調(diào)用
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;
{
viewA.frame=CGRectMake(50,0,100,400);
NSLog(@"scale between minimum and maximum. called after any 'bounce' animations");
}// scale between minimum and maximum. called after any 'bounce' animations
//如果你不是完全滾動(dòng)到滾軸視圖的頂部,你可以輕點(diǎn)狀態(tài)欄,那個(gè)可視的滾軸視圖會(huì)一直滾動(dòng)到頂部,那是默認(rèn)行為,你可以通過該方法返回NO來關(guān)閉它
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewShouldScrollToTop");
returnYES;
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidScrollToTop");
}