久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

UIScrollView 的靈敏度/滾動速度與分頁

Sensitivity/Scroll speed of UIScrollView with paging(UIScrollView 的靈敏度/滾動速度與分頁)
本文介紹了UIScrollView 的靈敏度/滾動速度與分頁的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我希望 UIScrollView 在快速掃過后快速滾動,像這樣.雖然,當打開分頁時,滾動一次一頁.是否可以在不使用手勢識別器手動實現的情況下通過手指輕彈啟用分頁時快速滾動?

I want UIScrollView to scroll fast after fast sweep, like this. Although, when paging is turned on, the scroll works one page at a time. Is it possible to scroll fast, when paging is enabled with a flick of a finger without manually implementation using gesture recognizers?

推薦答案

這很簡單,但是您必須自己實現分頁方面(這很簡單).您不需要手勢識別器.

This is fairly straightforward, however you must implement the paging aspect yourself (which is fairly simple). You don't need gesture recognizers.

首先,調整你的UIScrollView減速率:

First, adjust your UIScrollView deceleration rate:

scrollView.decelerationRate = UIScrollViewDecelerationRateFast

假設我們有一個內容數組——我們稱之為yourPagesArray.在您的 UIScrollViewDelegate 中,實現以下方法:

Assume we have an array of content — let's call it yourPagesArray. In your UIScrollViewDelegate, implement the following method:

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
{
    //This is the index of the "page" that we will be landing at
    let nearestIndex = Int(CGFloat(targetContentOffset.pointee.x) / scrollView.bounds.size.width + 0.5)

    //Just to make sure we don't scroll past your content
    let clampedIndex = max( min( nearestIndex, yourPagesArray.count - 1 ), 0 )

    //This is the actual x position in the scroll view
    var xOffset = CGFloat(clampedIndex) * scrollView.bounds.size.width

    //I've found that scroll views will "stick" unless this is done
    xOffset = xOffset == 0.0 ? 1.0 : xOffset

    //Tell the scroll view to land on our page
    targetContentOffset.pointee.x = xOffset
}

您還需要實現以下委托方法,以處理用戶輕輕抬起手指而不會導致任何滾動減速的情況:

You will also need to implement the following delegate method, to handle the case where the user lifts their finger gently without causing any scroll deceleration:

(更新:在最新的 iOS SDK 下您可能不需要這樣做.現在似乎在零速度時調用了上述委托方法.)

(Update: you may not need to do this under the latest iOS SDK. It seems like the above delegate method is now called when there is zero velocity.)

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)
{
    if !decelerate
    {
        let currentIndex = floor(scrollView.contentOffset.x / scrollView.bounds.size.width)

        let offset = CGPoint(x: scrollView.bounds.size.width * currentIndex, y: 0)

        scrollView.setContentOffset(offset, animated: true)
    }
}

目標-C

設置你的減速率:

Objective-C

Setting your deceleration rate:

scrollView.decelerationRate = UIScrollViewDecelerationRateFast;

然后你的滾動視圖委托實現:

Then your scroll view delegate implementation:

- (void) scrollViewWillEndDragging:(UIScrollView *)scroll withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
    //This is the index of the "page" that we will be landing at
    NSUInteger nearestIndex = (NSUInteger)(targetContentOffset->x / scrollView.bounds.size.width + 0.5f);   

    //Just to make sure we don't scroll past your content
    nearestIndex = MAX( MIN( nearestIndex, yourPagesArray.count - 1 ), 0 );

    //This is the actual x position in the scroll view
    CGFloat xOffset = nearestIndex * scrollView.bounds.size.width;

    //I've found that scroll views will "stick" unless this is done
    xOffset = xOffset==0?1:xOffset;

    //Tell the scroll view to land on our page
    *targetContentOffset = CGPointMake(xOffset, targetContentOffset->y);
}

- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if( !decelerate )
    {
        NSUInteger currentIndex = (NSUInteger)(scrollView.contentOffset.x / scrollView.bounds.size.width);

        [scrollView setContentOffset:CGPointMake(scrollView.bounds.size.width * currentIndex, 0) animated:YES];
    }
}

這篇關于UIScrollView 的靈敏度/滾動速度與分頁的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

iOS - Using storyboard and autolayout to center the UIScrollView(iOS - 使用故事板和自動布局使 UIScrollView 居中)
get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
UIScrollView zooming with Auto Layout(UIScrollView 使用自動布局縮放)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
主站蜘蛛池模板: 国产小网站 | 国产一区二区三区www | 中文字幕av在线 | a在线观看 | 97av视频| 99精品免费久久久久久日本 | 久久久久久亚洲精品 | 91色视频在线观看 | 国产精品国产三级国产aⅴ中文 | 亚洲日韩欧美一区二区在线 | 国产在线拍偷自揄拍视频 | 精品欧美一区二区久久久伦 | 日本精品一区二区三区在线观看 | 亚洲一区二区三区免费在线观看 | 国产精品久久久久久婷婷天堂 | 精品国产亚洲一区二区三区大结局 | 一区二区三区在线看 | 日日干天天操 | 黑人巨大精品 | 精品日韩| 青青草在线播放 | 亚洲国产成人av | 男女羞羞视频在线观看 | 国产一二区视频 | 激情毛片 | 久草网免费 | 精品国产一区二区国模嫣然 | 黄色免费av | www久久久| 精品免费国产一区二区三区 | 久久综合久色欧美综合狠狠 | 国内精品久久久久 | 午夜网站视频 | 免费在线h视频 | 欧美日韩综合视频 | 国产欧美日韩精品一区二区三区 | 中日av| 超碰成人免费 | 精品国产一区二区久久 | 精品久久久av | 久久aⅴ乱码一区二区三区 91综合网 |