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

循環 UIScrollView 但繼續減速

Loop UIScrollView but continue decelerating(循環 UIScrollView 但繼續減速)
本文介紹了循環 UIScrollView 但繼續減速的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我設置了一個無限滾動視圖,當它達到 0 內容偏移量時,我將其設置為最大內容偏移量,反之亦然.

I've set up an infinite scroll view and when it reaches 0 content offset I set it to max content offset and vice versa.

[scrollView setContentOffset:CGPointMake(0,0) animated:NO];

這可行,但它會阻止 UIScrollView 減速.

This works but it stops the UIScrollView decelerating.

有沒有辦法做到這一點,但保持 UIScrollView 減速?

Is there a way to do this but keep the UIScrollView decelerating?

我試過了……

float declerationRate = scrollView.decelerationRate;
[scrollView setContentOffset:CGPointMake(scrollView.frame.size.width, 0) animated:NO];
scrollView.decelerationRate = declerationRate;

但是沒有用.

編輯

我剛剛意識到 decelerationRate 是用于確定減速的慢/快的設置.

I just realised that decelerationRate is the setting to determine how slow/fast the deceleration is.

我需要的是從滾動視圖中獲取當前速度.

What I need is to get the current velocity from the scrollView.

推薦答案

是的,我不得不稍微調整一下這個想法.

Right I had to tweak the idea a bit.

原來嘗試設置 UIScrollView 的速度很困難……非常困難.

Turns out trying to set the velocity of a UIScrollView is difficult... very difficult.

所以無論如何,我有點調整它.

So anyway, I kind of tweaked it.

這實際上是一個迷你項目,在回答了別人的 SO 問題并認為我會嘗試自己解決之后.

This is actually a mini project after answering someone else's SO question and thought I'd try to solve it myself.

我想創建一個微調器應用程序,我可以滑動它來旋轉箭頭,使其旋轉并減速到一個點.

I want to create a spinner app that I can swipe to spin an arrow around so it spins and decelerates to a point.

我所做的是設置一個 UIImageView,箭頭朝上.

What I did was set up a UIImageView with the arrow pointing up.

那么覆蓋UIImageView的是一個UIScrollView.

Then covering the UIImageView is a UIScrollView.

然后在代碼中...

@interface MyViewController () <UIScrollViewDelegate>

@property (nonatomic, weak) IBOutlet UIScrollView *scrollView;
@property (nonatomic, weak) IBOutlet UIImageView *arrowView;

@end

@implementation MyViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //make the content size really big so that the targetOffset of the deceleration will never be met.
    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 100, self.scrollView.frame.size.height);
    //set the contentOffset of the scroll view to a point in the center of the contentSize.
    [self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width * 50, 0) animated:NO];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)rotateImageView
{
    //Calculate the percentage of one "frame" that is the current offset.

    // each percentage of a "frame" equates to a percentage of 2 PI Rads to rotate
    float minOffset = self.scrollView.frame.size.width * 50;
    float maxOffset = self.scrollView.frame.size.width * 51;

    float offsetDiff = maxOffset - minOffset;

    float currentOffset = self.scrollView.contentOffset.x - minOffset;

    float percentage = currentOffset / offsetDiff;

    self.arrowView.transform = CGAffineTransformMakeRotation(M_PI * 2 * percentage);
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //the scrollView moved so update the rotation of the image
    [self rotateImageView];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //the scrollview stopped moving.
    //set the content offset back to be in the middle
    //but make sure to keep the percentage (used above) the same
    //this ensures the arrow is pointing in the same direction as it ended decelerating

    float diffOffset = scrollView.contentOffset.x;

    while (diffOffset >= scrollView.frame.size.width) {
        diffOffset -= scrollView.frame.size.width;
    }

    [scrollView setContentOffset:CGPointMake(scrollView.frame.size.width * 50 + diffOffset, 0) animated:NO];
}

@end

這會產生像命運之輪一樣的旋轉器的預期效果,它將在任一方向無限旋轉.

This gives the desired effect of a spinner like on Wheel of Fortune that will spin endlessly in either direction.

雖然有一個缺陷.如果用戶不停地旋轉并不停地旋轉,則它只會在任一方向旋轉 50 次后才停止.

There is a flaw though. If the user keeps spinning and spinning without letting it stop it will only go 50 spins in either direction before coming to a stop.

這篇關于循環 UIScrollView 但繼續減速的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 欧美激情一区二区三区 | 伊人精品久久久久77777 | 国产99久久精品一区二区永久免费 | 一级大片 | 成人网址在线观看 | 成人免费观看男女羞羞视频 | 成人国产在线视频 | 亚洲精品久久久一区二区三区 | 欧美日韩一区二区三区视频 | 成人av网站在线观看 | 欧美日韩在线一区二区 | 日韩精品成人网 | 欧美日韩淫片 | 99视频在线免费观看 | 久久综合久久综合久久 | 一区二区三区在线观看免费视频 | 91文字幕巨乱亚洲香蕉 | 日日碰狠狠躁久久躁96avv | 亚洲国产成人精品久久久国产成人一区 | 中文字幕免费 | 日韩影音 | 一区二区三区视频在线免费观看 | 欧美日韩国产一区二区 | 久久综合一区二区三区 | 精品国产99 | 中文字幕国产视频 | 欧美综合一区二区三区 | 亚洲精品中文在线 | 国产一级电影网 | 在线观看 亚洲 | 精品久久久久久国产 | 99精品国产一区二区三区 | 亚洲成人精品一区 | 播放一级黄色片 | 免费视频一区二区三区在线观看 | 国产伦精品一区二区三区精品视频 | 夜夜精品浪潮av一区二区三区 | 亚洲精品一区二区三区中文字幕 | 1级黄色大片 | 欧美一级淫片免费视频黄 | 一区中文字幕 |