实现SlideView动画SlideFromTop和SlideFromBottom [英] Implementing SlideView Animation SlideFromTop and SlideFromBottom

查看:176
本文介绍了实现SlideView动画SlideFromTop和SlideFromBottom的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施SlideView动画,它将根据配置从顶部或底部滑动。

I am implementing SlideView animation which will slide from top or bottom depending on the configuration.

对于slideFromTop,它的工作原理非常好。对于slideFromBottom,它仅显示幻灯片视图的一半。这是我的SlideViewController。

For the slideFromTop it works perfectly fine. For slideFromBottom it only shows half of the slide view. Here is my SlideViewController.

const int VIEW_HEIGHT = 44; 

-(void) slideInFromBottom 
{
    CGRect screenSize = [[UIScreen mainScreen] bounds];

    self.view.frame = CGRectMake(0,screenSize.size.height, self.view.frame.size.width, VIEW_HEIGHT);

    [UIView animateWithDuration:2.0 animations:^{

        self.view.frame = CGRectMake(0, screenSize.size.height - VIEW_HEIGHT, self.view.frame.size.width,VIEW_HEIGHT);

    } completion:^(BOOL finished) {

        [UIView animateWithDuration:2.0 delay:2.0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{

            self.view.frame = CGRectMake(0, screenSize.size.height, self.view.frame.size.width, VIEW_HEIGHT); 

        } completion:^(BOOL finished) {

        }];


    }];

}

-(void) slideInFromTop
{
    self.view.frame = CGRectMake(0, (-1) * VIEW_HEIGHT, self.view.frame.size.width, VIEW_HEIGHT);

    CGRect temp = self.view.frame;

    [UIView animateWithDuration:2.0 animations:^{

        self.view.frame = CGRectMake(0, 0, self.view.frame.size.width,VIEW_HEIGHT);

    } completion:^(BOOL finished) {

        [UIView animateWithDuration:2.0 delay:2.0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{

            self.view.frame = temp;

        } completion:^(BOOL finished) {

        }];


    }];

}

用户使用以下代码调用SlideViewController:

The user calls the SlideViewController using the following code:

-(IBAction) save:(id) sender 
{
    SlideViewController *slideViewController = [[SlideViewController alloc] initWithTitle:@"Customer has been saved!" animationType:SlideInFromTop];
    [self.view addSubview:slideViewController.view];
} 

更新2:

 self.view.frame = CGRectMake(0, screenSize.size.height - (1.3 * VIEW_HEIGHT), self.view.frame.size.width,VIEW_HEIGHT);


推荐答案

省去一些麻烦,只需下载并安装 FTUtils

Save yourself some trouble and just download and install FTUtils

只需将项目放入您的项目中,包括标题,然后你可以在一行中做动画:

Just drop the project into yours, include the header, then you can do the animation in one line:

[myVu slideInFrom:kFTAnimationTop duration:0.75f delegate:self];

它有十几个非常有用的动画,比如UIAlertViews的pop in效果。我一直都在使用它。

It has over a dozen very useful animations like the "pop in" effect on UIAlertViews. I litteraly use it all the time.

这篇关于实现SlideView动画SlideFromTop和SlideFromBottom的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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