您好,登錄后才能下訂單哦!
// 觸摸屏幕來滾動畫面還是其他的方法使得畫面滾動,皆觸發(fā)該函數(shù)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"Scrolling...");
}
// 觸摸屏幕并拖拽畫面,再松開,最后停止時,觸發(fā)該函數(shù)
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"scrollViewDidEndDragging - End of Scrolling.");
}
// 滾動停止時,觸發(fā)該函數(shù)
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidEndDecelerating - End of Scrolling.");
}
// 調(diào)用以下函數(shù),來自動滾動到想要的位置,此過程中設(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.");
}
首先實現(xiàn)UIScrollViewDelegate協(xié)議:
[plain] view plaincopy
#import <UIKit/UIKit.h>
@interface Activity01ViewController : UIViewController<UIScrollViewDelegate>{
UIScrollView *myscrollview;
}
@property (nonatomic,retain) UIScrollView *myscrollview;
@end
對myscrollview進行初始化:
[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; //只能一個方向滑動
myscrollview.pagingEnabled = NO; //是否翻頁
myscrollview.backgroundColor = [UIColor blackColor];
myscrollview.showsVerticalScrollIndicator =YES; //垂直方向的滾動指示
myscrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滾動指示的風格
myscrollview.showsHorizontalScrollIndicator = NO;//水平方向的滾動指示
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)控目前滾動的位置
CGSize contentSize 滾動范圍的大小
UIEdgeInsets contentInset 視圖在scrollView中的位置
id<UIScrollerViewDelegate> delegate 設(shè)置協(xié)議
BOOL directionalLockEnabled 指定控件是否只能在一個方向上滾動
BOOL bounces 控制控件遇到邊框是否反彈
BOOL alwaysBounceVertical 控制垂直方向遇到邊框是否反彈
BOOL alwaysBounceHorizontal 控制水平方向遇到邊框是否反彈
BOOL pagingEnabled 控制控件是否整頁翻動
BOOL scrollEnabled 控制控件是否能滾動
BOOL showsHorizontalScrollIndicator 控制是否顯示水平方向的滾動條
BOOL showsVerticalScrollIndicator 控制是否顯示垂直方向的滾動條
UIEdgeInsets scrollIndicatorInsets 指定滾動條在scrollerView中的位置
UIScrollViewIndicatorStyleindicatorStyle 設(shè)定滾動條的樣式
float decelerationRate 改變scrollerView的減速點位置
BOOL tracking 監(jiān)控當前目標是否正在被跟蹤
BOOL dragging 監(jiān)控當前目標是否正在被拖拽
BOOL decelerating 監(jiān)控當前目標是否正在減速
BOOL delaysContentTouches 控制視圖是否延時調(diào)用開始滾動的方法
BOOL canCancelContentTouches 控制控件是否接觸取消touch的事件
float minimumZoomScale 縮小的最小比例
float maximumZoomScale 放大的最大比例
float zoomScale 設(shè)置變化比例
BOOL bouncesZoom 控制縮放的時候是否會反彈
BOOL zooming 判斷控件的大小是否正在改變
BOOL zoomBouncing 判斷是否正在進行縮放反彈
BOOL scrollsToTop 控制控件滾動到頂部
注意:
1、使scrollview不要上下滑動,可以設(shè)置
scrollview.contentSize = CGSizeMake(你要的長度, 0);
協(xié)議方法解釋:
[plain] view plaincopy
#pragma mark UIScrollViewDelegate
//只要滾動了就會觸發(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");
}
//將開始降速時
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewWillBeginDecelerating");
}
//減速停止了時執(zhí)行,手觸摸時執(zhí)行執(zhí)行
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidEndDecelerating");
}
//滾動動畫停止時執(zhí)行,代碼改變時出發(fā),也就是setContentOffset改變時
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidEndScrollingAnimation");
}
//設(shè)置放大縮小的視圖,要是uiscrollview的subview
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
{
NSLog(@"viewForZoomingInScrollView");
return viewA;
}
//完成放大縮小時調(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
//如果你不是完全滾動到滾軸視圖的頂部,你可以輕點狀態(tài)欄,那個可視的滾軸視圖會一直滾動到頂部,那是默認行為,你可以通過該方法返回NO來關(guān)閉它
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewShouldScrollToTop");
returnYES;
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidScrollToTop");
}
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。