从下到上动画UIView高度

ban*_*isa 12 animation uiview ios

我正在做一个UIView高度的简单动画,以便它显示出来.

默认情况下,它似乎从上到下显示,我希望它从下到上显示.

我把UIView固定在屏幕的底部.

我确定它很简单,我很遗憾.....任何提示?

谢谢

atr*_*eat 10

我真的认为实现这一目标的最简单方法是为视图的高度和y属性设置动画.如果它们沿着相同的曲线发生,它应该看起来完全无缝到用户.当您将高度设置为0时,也会将y分量设置为原始y +原始高度的动画.

UIView *view = ...;
float originalY = view.frame.origin.y;
float originalH = view.bounds.size.height;

[UIView animateWithDuration:1.2f delay:1.0f options:UIViewAnimationCurveEaseInOut animations:^{
    view.frame = CGRectMake(view.frame.origin.x, (originalY + originalH), view.bounds.size.width, 0);

}completion:^(BOOL finished) {
    NSLog(@"Animation is complete");
}];
Run Code Online (Sandbox Code Playgroud)

我相信这会给出一个倒塌视图的外观和感觉.我没有在代码中尝试过这个,但我认为没有理由不这样做.


War*_*shi 9

隐藏在底部

[self animateViewHeight:myView withAnimationType:kCATransitionFromBottom];
Run Code Online (Sandbox Code Playgroud)

用于反向动画

[self animateViewHeight:myView withAnimationType:kCATransitionFromTop];
Run Code Online (Sandbox Code Playgroud)

...

- (void)animateViewHeight:(UIView*)animateView withAnimationType:(NSString*)animType {  
    CATransition *animation = [CATransition animation];
    [animation setType:kCATransitionPush];
    [animation setSubtype:animType];

    [animation setDuration:0.5];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    [[animateView layer] addAnimation:animation forKey:kCATransition];
    animateView.hidden = !animateView.hidden;
}
Run Code Online (Sandbox Code Playgroud)


ban*_*isa 5

就像有骨头的狗我想出来了......

我没有动画帧高度,而是将变换应用于视图并设置图层的锚点.

//set the anchor point to the bottom of the view
[self setAnchorPoint:CGPointMake(0.5, 1.0) forView:hostView];
//Scale the height to close to zero
hostView.transform = CGAffineTransformMakeScale(1, 0.00001);
Run Code Online (Sandbox Code Playgroud)

如果我将0作为y比例,则视图表现得很奇怪....在动画结束时我只是将其设置为隐藏.

在备份的路上我只使用身份转换(重置它)

hostView.transform = CGAffineTransformIdentity;
Run Code Online (Sandbox Code Playgroud)

请注意,更改我的锚点会改变我的视图位置.有关setAnchorPoint方法的信息,请参阅此文章,该方法在设置anchorPoint后对视图进行规范化

更改我的CALayer的anchorPoint会移动视图