// 觸摸屏幕來(lái)滾動(dòng)畫(huà)面還是其他的方法使得畫(huà)面滾動(dòng),皆觸發(fā)該函數(shù)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"Scrolling...");
}
// 觸摸屏幕并拖拽畫(huà)面,再松開(kāi),最后停止時(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ù),來(lái)自動(dòng)滾動(dòng)到想要的位置,此過(guò)程中設(shè)置有動(dòng)畫(huà)效果,停止時(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)用開(kāi)始滾動(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);
}
//開(kāi)始拖拽視圖
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewWillBeginDragging");
}
//完成拖拽
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
{
NSLog(@"scrollViewDidEndDragging");
}
//將開(kāi)始降速時(shí)
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewWillBeginDecelerating");
}
//減速停止了時(shí)執(zhí)行,手觸摸時(shí)執(zhí)行執(zhí)行
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidEndDecelerating");
}
//滾動(dòng)動(dòng)畫(huà)停止時(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)行為,你可以通過(guò)該方法返回NO來(lái)關(guān)閉它
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewShouldScrollToTop");
returnYES;
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidScrollToTop");
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。