UIView动画向下滑动

den*_*bec 5 iphone animation objective-c uiview uiviewanimation

我试图在UIImageView中向下滑动图像,但我不知道UIContentMode和动画属性的哪个组合是正确的.图像应始终具有相同的大小,不应该拉伸...我想要的是,首先看不到任何内容,然后框架延伸并显示图像.

如果你明白我的意思,也许会更容易:

我的问题的插图

所以,这听起来相当简单,但我应该为UIImageView使用什么UIContentMode以及我应该制作什么属性?谢谢!

Mig*_*elB 8

我带头做了一个截屏视频.这是你的想法吗?

我把动画无限重复,这样就可以更容易地用视频捕捉,但它可以通过按下按钮开始,也可以冻结到位,显示弹出窗口及其内容,直到反转再次隐藏.

我使用了Core Animation,而不是动画UIView,因为我想使用CALayer的mask属性隐藏弹出窗口并用滑动动画显示它.

这是我使用的代码(与视频中相同):

- (void)viewDidLoad
{

    // Declaring the popover layer
    CALayer *popover = [CALayer layer];

    CGFloat popoverHeight = 64.0f;
    CGFloat popoverWidth = 200.0f;

    popover.frame = CGRectMake(50.0f, 100.0f, popoverWidth, popoverHeight);
    popover.contents = (id) [UIImage imageNamed:@"popover.png"].CGImage;

    // Declaring the mask layer
    CALayer *maskLayer = [CALayer layer];
    maskLayer.frame = CGRectMake(0, - popoverHeight, popoverWidth, popoverHeight);
    maskLayer.backgroundColor = [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f].CGColor;

    // Setting the animation (animates the mask layer)
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.y"];
    animation.byValue = [NSNumber numberWithFloat:popoverHeight];
    animation.repeatCount = HUGE_VALF;
    animation.duration = 2.0f;

    [maskLayer addAnimation:animation forKey:@"position.y"];

    //Assigning the animated maskLayer to the mask property of your popover
    popover.mask = maskLayer;

    [self.view.layer addSublayer:popover];

    [super viewDidLoad];
}
Run Code Online (Sandbox Code Playgroud)

注意:您必须将QuartzCore框架导入项目并在头文件中写入此行:#import <QuartzCore/QuartzCore.h>.

告诉您这是否适合您,或者您是否需要更多帮助进行设置.