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

UIScrollview 動畫取決于內容偏移

UIScrollview animation depending on content offset(UIScrollview 動畫取決于內容偏移)
本文介紹了UIScrollview 動畫取決于內容偏移的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用水平 UIScrollView,并且我想要根據內容偏移的 x 值進行背景顏色轉換.

I'm using a horizontal UIScrollView, and I want a background color transition depending on the x value of the content offset.

示例: UIScrollView 的寬度為 640px.當內容偏移量等于 0px 時,背景顏色必須為紅色.當內容偏移為 320 px 時,背景必須為黃色.但最重要的是,當 UIScrollview 在 0px 和 320px 之間時,背景顏色必須在紅色和黃色之間.

Example: The width of UIScrollView is 640px. When the content offset is equal to 0px, the background color must be red. When the content offset is 320 px, the background must be yellow. But the most important part is, when the UIScrollview is between 0px and 320px the background color must be between red and yellow.

提示:當您從搜索中向左滑動時,iOS 的 twitter 應用程序具有相同的動畫.導航上的標簽稍微消失了.

推薦答案

你需要根據偏移百分比來創建顏色.

You need to create the colour depending on the offset percentage.

在這種顏色之間創建轉換的最簡單方法是使用 HSB 顏色空間.

The easiest way to create a shift between colours like this is to use the HSB colour space.

另外,這不是動畫.動畫"效果由滾動視圖提供給您.您只需要在每次滾動視圖更改時設置顏色即可.

Also, this isn't an animation. The "animation" effect is given to you by the scrollview. You just need to set the colour every time the scroll view changes.

在委托方法中你可以做這樣的事情.

In the delegate method you could do something like this.

修改以提高靈活性

// this just calculates the percentages now and passes it off to another method.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // vertical
    CGFloat maximumVerticalOffset = scrollView.contentSize.height - CGRectGetHeight(scrollView.frame);
    CGFloat currentVerticalOffset = scrollView.contentOffset.y;

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

    // percentages
    CGFloat percentageHorizontalOffset = currentHorizontalOffset / maximumHorizontalOffset;
    CGFloat percentageVerticalOffset = currentVerticalOffset / maximumVerticalOffset;

    [self scrollView:scrollView didScrollToPercentageOffset:CGPointMake(percentageHorizontalOffset, percentageVerticalOffset)];
}

// this just gets the percentage offset.
// 0,0 = no scroll
// 1,1 = maximum scroll
- (void)scrollView:(UIScrollView *)scrollView didScrollToPercentageOffset:(CGPoint)percentageOffset
{
    UIColor *HSBColor = [self HSBColorForOffsetPercentage:percentageOffset.x];

    UIColor *RGBColor = [self RGBColorForOffsetPercentage:percentageOffset.x];
}

// HSB color just using Hue
- (UIColor *)HSBColorForOffsetPercentage:(CGFloat)percentage
{
    CGFloat minColorHue = 0.0;
    CGFloat maxColorHue = 0.2; // this is a guess for the yellow hue.

    CGFloat actualHue = (maxColorHue - minColorHue) * percentage + minColorHue;

    // change these values to get the colours you want.
    // I find reducing the saturation to 0.8 ish gives nicer colours.
    return [UIColor colorWithHue:actualHue saturation:1.0 brightness:1.0 alpha:1.0];
}

// RGB color using all R, G, B values
- (UIColor *)RGBColorForOffsetPercentage:(CGFloat)percentage
{
    // RGB 1, 0, 0 = red
    CGFloat minColorRed = 1.0;
    CGFloat minColorGreen = 0.0;
    CGFloat minColorBlue = 0.0;

    // RGB 1, 1, 0 = yellow
    CGFloat maxColorRed = 1.0;
    CGFloat maxColorGreen = 1.0;
    CGFloat maxColorBlue = 0.0;

    // if you have specific beginning and end RGB values then set these to min and max respectively.
    // it should even work if the min value is greater than the max value.

    CGFloat actualRed = (maxColorRed - minColorRed) * percentage + minColorRed;
    CGFloat actualGreen = (maxColorGreen - minColorGreen) * percentage + minColorGreen;
    CGFloat actualBlue = (maxColorBlue - minColorBlue) * percentage + minColorBlue;

    return [UIColor colorWithRed:actualRed green:actualGreen blue:actualBlue alpha:1.0];
}

我不知道 RGB 方法在中間值上的表現如何.它可能會在中間變成棕色等等......但你可以玩.

I don't know how the RGB method will perform on mid values. It may go brown in the middle etc... but you can play around.

這應該讓您了解如何使用滾動視圖為 ANYTHING 設置動畫以作為控制它的一種方式.

This should give you an idea of how to animate ANYTHING using the scroll view as a way to control it.

使用這種方法,您可以控制不透明度、大小、旋轉、字體大小等...您甚至可以組合多種事物(就像我對 RGB 所做的那樣).

Using this method you can control the opacity, size, rotation, font size, etc... You can even combine multiple things (like I did with RGB).

這篇關于UIScrollview 動畫取決于內容偏移的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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 可縮放?)
UIImageView zoom and pinch in UIScrollView(UIImageView 在 UIScrollView 中縮放和捏合)
主站蜘蛛池模板: 亚洲男女视频在线观看 | 久久三区 | 成人美女免费网站视频 | 国产精品18毛片一区二区 | 亚洲伊人精品酒店 | 狠狠干av| 国产伦精品一区二区三区精品视频 | 日本一区二区不卡视频 | 精品一区二区三区视频在线观看 | 亚洲高清免费观看 | 免费视频一区 | 国产精品久久久久久久久久久久久 | 91在线视频播放 | 国产成人aⅴ| 欧美亚洲在线 | 亚洲精品久久久一区二区三区 | 国产一级片在线观看视频 | 91精品国产日韩91久久久久久 | 国内自拍第一页 | 久久久精品天堂 | 午夜免费福利影院 | 91精品国产乱码久久久久久久久 | 日本高清中文字幕 | www.亚洲| 久久精品久久精品 | 黄色毛片网站在线观看 | 性高朝久久久久久久3小时 av一区二区三区四区 | 在线精品一区 | 91看片在线观看 | 国产精品成人国产乱一区 | h在线观看| www.日韩 | av黄色在线播放 | 午夜久久久 | 成人黄色电影在线播放 | 久久久久国| 国产精品国产a级 | 久久久久久色 | av激情影院 | 成人国产在线观看 | 天天爱天天操 |