久久久久久久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 可縮放?)
主站蜘蛛池模板: 日韩欧美一级片 | 欧美精品第一页 | 黄色毛片网站在线观看 | 亚洲精品99 | 91精品国产综合久久久久久蜜臀 | 成人国产精品免费观看 | 亚洲视频在线看 | 人人叉| 国产精品美女视频 | 拍拍无遮挡人做人爱视频免费观看 | 欧美黄视频 | 国产成人精品免高潮在线观看 | 三级成人片 | 精品美女视频在免费观看 | 日韩国产中文字幕 | 日韩1区| 91成人免费观看 | av永久免费 | 国产www在线 | 久久九九免费 | 毛片99| 懂色av蜜桃av | 欧美一卡二卡在线观看 | 日韩精品激情 | 久久久久久久久国产成人免费 | 中文精品一区二区 | 九九热精品在线 | 国产精品色一区二区三区 | 日韩欧美在线观看 | www.99久久.com | 台湾佬久久| 人人爽人人草 | 91精品一区| 中文亚洲视频 | 欧美日韩一区二区电影 | 一区二区三区四区在线视频 | 色综合久久天天综合网 | 亚洲精品视频一区 | 毛片网站在线观看 | 欧美日韩久久 | 国产免费一区二区三区网站免费 |