久久久久久久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.

任何幫助將不勝感激.任何實(shí)現(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 模擬器上運(yùn)行時,使用 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 可縮放?)
主站蜘蛛池模板: 免费看黄视频网站 | 久久久久国产一区二区三区 | 91精品久久久久久久久中文字幕 | 天天射中文 | 亚洲精精品 | 久久噜噜噜精品国产亚洲综合 | 国产98色在线 | 日韩 | 日韩欧美国产精品一区二区三区 | 毛片免费在线 | 亚洲欧美日韩久久 | 国产成人精品午夜视频免费 | 国产激情一区二区三区 | 中文在线日韩 | 精品福利在线 | 久久精品视频免费观看 | 天天色综 | 久久精品亚洲欧美日韩久久 | 中文字幕一区在线观看视频 | 欧美精品日韩 | 女生羞羞网站 | 美女福利视频一区 | 日韩电影免费在线观看中文字幕 | 欧美一区二区另类 | 欧美不卡一区 | 国产福利二区 | 日韩成人在线播放 | 午夜久久久久久久久久一区二区 | 欧美狠狠操 | 欧美a级成人淫片免费看 | 欧美激情在线精品一区二区三区 | 综合久久综合久久 | 91精品国产综合久久久动漫日韩 | 日韩伦理一区二区三区 | 天天拍天天操 | 激情五月婷婷丁香 | 国产小视频在线观看 | 日韩免费视频 | 日韩欧美专区 | 91精品国产综合久久久久久丝袜 | h视频在线播放 | 成人午夜看片 |