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

在滾動期間更改背景顏色

Make background color change during scroll(在滾動期間更改背景顏色)
本文介紹了在滾動期間更改背景顏色的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我的應(yīng)用有一個入門部分,其中包含 4 個頁面,用戶可以水平滾動以了解如何使用該應(yīng)用(標(biāo)準(zhǔn)).我希望當(dāng)用戶從一個頁面滾動到另一個頁面時背景顏色會發(fā)生變化.

I have an onboarding section of my app with 4 pages the users scrolls through horizontally to get an idea of how to use the app (standard). I want the background color to transition as the user scrolls from page to page.

我想要使用 4 個 RGB 值:

I have the 4 RGB values I want to use:

241,170,170

241,170,170

170,201,241

170,201,241

188,170,241

188,170,241

241,199,170

241,199,170

我知道我必須使用滾動視圖委托 + 內(nèi)容偏移來更改 uicolor 值,但我不確定如何讓它轉(zhuǎn)到我選擇的特定顏色.

I know I must use the scroll view delegate + content offset to change the uicolor values, but im not sure how I get it to go to the specific colors ive selected.

任何幫助將不勝感激.任何實現(xiàn)都可以,快速或客觀-c

Any help would be greatly appreciated. Any implementation would do, swift or objective-c

謝謝

推薦答案

對于任何有興趣的人.這就是解決方案.我結(jié)合了我在堆棧上找到的一些答案并將其調(diào)整為使用 4 種顏色

For anyone interested. This is the solution. I combined some answers I found on stack and adapted it to use 4 colors

- (void)scrollViewDidScroll:(UIScrollView *)scrollView  {
CGFloat pageWidth = self.scrollView.frame.size.width;
float fractionalPage = self.scrollView.contentOffset.x / pageWidth;
NSInteger page = lround(fractionalPage);
self.pageControl.currentPage = page;

// horizontal
CGFloat maximumHorizontalOffset = scrollView.contentSize.width - CGRectGetWidth(scrollView.frame);
CGFloat currentHorizontalOffset = scrollView.contentOffset.x;

// percentages
CGFloat percentageHorizontalOffset = currentHorizontalOffset / maximumHorizontalOffset;

NSLog(@"content offfset: %f", percentageHorizontalOffset);

if (percentageHorizontalOffset < 0.333333) {
    self.view.backgroundColor = [self fadeFromColor:self.colorArray[0] toColor:self.colorArray[1] withPercentage:percentageHorizontalOffset*3];
} else if (percentageHorizontalOffset >= 0.333333 && percentageHorizontalOffset < 0.666667) {
    self.view.backgroundColor = [self fadeFromColor:self.colorArray[1] toColor:self.colorArray[2] withPercentage:(percentageHorizontalOffset-0.333333)*3];
} else if (percentageHorizontalOffset >= 0.666667) {
    self.view.backgroundColor = [self fadeFromColor:self.colorArray[2] toColor:self.colorArray[3] withPercentage:(percentageHorizontalOffset-0.666667)*3];
}
}

- (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];
}    

這篇關(guān)于在滾動期間更改背景顏色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設(shè)置滾動視圖內(nèi)容大小)
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 構(gòu)建會導(dǎo)致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創(chuàng)建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 亚洲男人天堂网 | 日韩在线观看中文字幕 | 欧美日韩免费视频 | 国产亚洲一区二区三区 | xxxx色| 五月伊人网 | 成人视屏在线观看 | japanese极品丰满少妇 | 色偷偷噜噜噜亚洲男人 | 精品免费观看 | 日韩色综合 | 免费精品 | 亚洲成人精品在线观看 | 久久久久久久综合 | 激情av网 | 99这里有精品 | 在线黄色网| 亚洲欧美日韩国产精品 | 中文字幕免费视频 | 黄色三级在线 | 黄网站免费观看 | 中文字幕精品在线观看 | 国产成人在线免费视频 | 免费观看一区二区 | 在线免费黄色网址 | 欧美激情综合 | 国产一区二区三区免费视频 | 亚洲看片 | 精品欧美一区二区精品久久 | 国产a精品 | 国产精品一二 | 日韩国产一区 | 欧美另类z0zx974 | 97在线观看免费视频 | 波多野结衣一区二区三区 | 欧美日韩久久久 | 亚洲成人久久久 | 在线免费看a| 国产成年妇视频 | 国产福利一区二区 | 日韩av在线免费看 |