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

根據 UIScrollView 的 contentOffset 改變顏色

Changing between colors based on UIScrollView#39;s contentOffset(根據 UIScrollView 的 contentOffset 改變顏色)
本文介紹了根據 UIScrollView 的 contentOffset 改變顏色的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個寬度為 960 的水平 UIScrollView,足以容納 3 個 UIViewController 視圖.

I have a horizontal UIScrollView that has a width of 960, enough to hold 3 UIViewController view's.

每個視圖都只有一個背景顏色.第一個是粉紅色,第二個是藍色,第三個是綠色.

Each view simply has a background color. The first is pink, the second is blue, and the third is green.

我想在用戶滾動時將可見顏色混合/混合/淡化.

I want to blend/mix/fade the visible colors together as the user scrolls.

因此,如果您從第 1 頁(粉紅色)滾動到第 2 頁(藍色),當用戶完全滑動到最終到達最終藍色之前,會出現某種類型的粉紅色和藍色混合/混合/淡入淡出第二頁.

So if you were scrolling from page 1 (pink) to page 2 (blue), there would be some type of mix/blend/fade of pink and blue before finally landing on the final blue color when the user fully swiped to the 2nd page.

我發現了一個關于我正在嘗試做什么的問題,并且我已經實現了可以在此處找到的答案:https://stackoverflow.com/a/26159561/3344977

I found a question about exactly what I'm trying to do, and I have implemented the answer which can be found here: https://stackoverflow.com/a/26159561/3344977

這個答案確實有效,我唯一的問題是這個答案只是為使用 2 個屏幕/顏色而創建的,而我有 3 個屏幕/顏色.

This answer does work, my only problem is this answer was only created to use 2 screens/colors, and I have 3 screens/colors.

我了解此答案的基礎知識,并且它依賴于 UIScrollView 的 contentOffset.x 來計算當前顏色,但除此之外,我的數學很糟糕,這讓我無法弄清楚如何修改它以使用第三種顏色.

I understand the basics of this answer and that it depends on the UIScrollView's contentOffset.x to calculate the current color, but other than that I am terrible at math which is holding me back from figuring out how to modify this to use a third color.

推薦答案

是的,你絕對可以將它用于三種(或更多)顏色.

Yes you can definitely use this for three colours (or more).

對于三種顏色(例如紅色、綠色、藍色),紅色為 0.0,綠色為 0.5,藍色為 1.0.所以你只需要在兩個淡入淡出之間分離方法(紅綠和綠藍將分別計算).

For three colours (say red, green, blue) you will have red at 0.0, green at 0.5 and blue at 1.0. So you just have to split off the method between the two fades (red-green and green-blue will be calculated separately).

在獲得方法之前使用我的代碼...

Using my code from before you get the method...

// this just gets the percentage offset.
// 0,0 = no scroll
// 1,1 = maximum scroll
- (void)scrollView:(UIScrollView *)scrollView didScrollToPercentageOffset:(CGPoint)percentageOffset
{
    // get your colours to fade between
    NSArray *colours = @[[UIColor redColor], [UIColor yellowColor], [UIColor purpleColor]];

    // choose the colours to fade between based on the percentage.
    if (percentageOffset.x < 0.5) {
        // multiply the offset by 2 because we want 0.5 to be 100%
        self.backgroundColor = [self fadeFromColor:colours[0] toColor:colours[1] withPercentage:percentageOffset.x*2];
    } else {
        // minus 0.5 because we want 0.5 to be 0%
        self.backgroundColor = [self fadeFromColor:colours[1] toColor:colours[2] withPercentage:(percentageOffset.x-0.5)*2];
    }
}

// this is a more generic method to fade between two colours
// it allows the colours to be passed in as parameters
- (UIColor *)fadeFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor withPercentage:(CGFloat)percentage
{
    // get the RGBA values from the colours
    CGFloat fromRed, fromGreen, fromBlue, fromAlpha;
    [fromColor getRed:&fromRed green:&fromGreen blue:&fromBlue alpha:&fromAlpha];

    CGFloat toRed, toGreen, toBlue, toAlpha;
    [toColor getRed:&toRed green:&toGreen blue:&toBlue alpha:&toAlpha];

    //calculate the actual RGBA values of the fade colour
    CGFloat red = (toRed - fromRed) * percentage + fromRed;
    CGFloat green = (toGreen - fromGreen) * percentage + fromGreen;
    CGFloat blue = (toBlue - fromBlue) * percentage + fromBlue;
    CGFloat alpha = (toAlpha - fromAlpha) * percentage + fromAlpha;

    // return the fade colour
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

這將在所有三種顏色之間很好地褪色.

This will fade nicely between all three colours.

您可以為此添加更多顏色并更改其拆分百分比的方式.

You can add more colours to this and change how it splits up the percentages.

這篇關于根據 UIScrollView 的 contentOffset 改變顏色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 可縮放?)
主站蜘蛛池模板: 久久一及片 | 91精品国产91久久久久久吃药 | 日韩视频在线观看一区二区 | 精品日韩一区 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 国产91 在线播放 | 国产精品自产拍 | 精品一区二区三区在线视频 | 国产丝袜一区二区三区免费视频 | 日韩区 | 爱爱无遮挡 | 国产999在线观看 | 黑人巨大精品欧美一区二区免费 | 亚洲区一 | 在线观看成人免费视频 | 欧美久久久久 | 成人久草| 操久久 | 欧美日韩在线精品 | 国产高清区 | 成人免费视频 | 黄色大片免费网站 | 亚洲成人高清 | 日本免费一区二区三区四区 | www.中文字幕 | 国内精品久久久久久影视8 最新黄色在线观看 | 国产日韩欧美91 | 麻豆91精品91久久久 | 欧美成人精品一区二区男人看 | 国产在线激情视频 | 亚洲欧美日韩成人在线 | 亚洲国产精品99久久久久久久久 | 涩涩视频网站在线观看 | 国产精品国产三级国产播12软件 | hitomi一区二区三区精品 | 欧美在线一区二区三区四区 | 韩日有码| 99精品国产成人一区二区 | 黑人成人网 | 国产一区二区麻豆 | 成人免费视频网站在线看 |