实现SlideView Animation SlideFromTop和SlideFromBottom

我正在实现SlideViewanimation,将根据configuration从顶部或底部滑动。

对于slideFromTop它工作得很好。 对于slideFromBottom,它只显示幻灯片视图的一半。 这是我的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:

 -(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

只需将项目拖放到您的项目中,包含标题,然后就可以在一行中执行animation:

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

它有十几个非常有用的animation,比如UIAlertViews中的“popup”效果。 我一直使用它。

我创build了一个名为MFSlidingView的库,有些人可能会觉得有用。