UIScrollView iOS应用中的动画 [英] Animation in UIScrollView iOS app

查看:62
本文介绍了UIScrollView iOS应用中的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用,我有一个全屏UIScrollView,顶部是UIImageView,底部是2 UIButton.

当用户滚动时,我想在图像视图上插入动画(也许只是逐渐更改alpha参数).

动画与滚动视图相关,例如,如果用户将滚动视图滚动一半,将仅显示一半动画.

我希望我能自我解释.

我该怎么做?

解决方案

使用UIScrollViewDelegate scrollViewDidScroll:方法.

https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intfm/UIScrollViewDelegate/scrollViewDidScroll :

还要检查该委托中的其他方法.

因此,举例来说,您可能会得到类似的结果(或将其更改为您的需求):

-(void)scrollViewDidScroll:(UIScrollView*)scrollView {

    float opacity = ( 100 - scrollView.contentOffset.y ) / 100.0; 
    opacity = (opacity < 0? 0 : opacity>1? 1 : opacity);
    imageView.layer.opacity = opacity;

}

您可能还想向Apple工程师学习.观看WWDC视频,其中有很多:

  • 在iOS 7上浏览滚动视图(WWDC 2013)
  • 通过滚动视图增强用户体验(WWDC 2012)
  • 高级ScrollView技术(WWDC 2011)

I'm developing an iOS app and i have a full screen UIScrollView with a UIImageView at the top and 2 UIButton in the bottom.

When the user scrolls i want to insert an animation on the image view (maybe only change the alpha parameter gradually).

The animation is correlated with the scrollview, for example, if the user scrolls the scrollview half, will be displayed only half animation.

I hope I explained myself.

How can i do this?

解决方案

Use the UIScrollViewDelegate scrollViewDidScroll: method.

https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intfm/UIScrollViewDelegate/scrollViewDidScroll:

But also check out other methods in that delegate.

So for example, you may end up with something like (or change this to your needs):

-(void)scrollViewDidScroll:(UIScrollView*)scrollView {

    float opacity = ( 100 - scrollView.contentOffset.y ) / 100.0; 
    opacity = (opacity < 0? 0 : opacity>1? 1 : opacity);
    imageView.layer.opacity = opacity;

}

You might also want to learn from Apple engineers themselves. Check out the WWDC videos, there are many of them:

  • Exploring Scroll Views on iOS 7 (WWDC 2013)
  • Enhancing User Experience with Scroll Views (WWDC 2012)
  • Advanced ScrollView Techniques (WWDC 2011)

这篇关于UIScrollView iOS应用中的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆