如何让我的视图缩小并消失?

时间:2011-05-18 16:50:54

标签: iphone cocoa-touch uiview uiviewcontroller core-animation

当我的用户按下按钮时,我希望可见视图缩小并消失,从而显示下面的父视图。目前我有这个,几乎可以工作:

-(void)deleteNoteTransition
{
    self.view.userInteractionEnabled=NO;
    [UIView beginAnimations:@"deleteNote" context:nil];
    [UIView setAnimationDuration:0.6];
    self.view.transform=CGAffineTransformMakeScale(0.01,0.01);
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:)];
    [UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)anim finished:(BOOL)flag
{
    self.view.userInteractionEnabled=YES;
    if ([anim isEqualToString:@"deleteNote"]) {
    [self.navigationController popViewControllerAnimated:YES];
    }
}

然而,有两个问题:

  • 缩小视图不是“整体”视图 - 它不包括标题栏和工具栏。
  • 视图缩小以显示纯白色背景,然后才触发第二个方法,因此白色背景会被父视图毫不客气地替换。

有没有办法包含整个屏幕并平滑地显示后面的父视图控制器,而没有进入OpenGL的东西,这对我目前的编程水平来说太复杂了?

1 个答案:

答案 0 :(得分:2)

这应该捕捉到你的整个观点:

#import <QuartzCore/QuartzCore.h>
UIGraphicsBeginImageContext(viewToCapture.bounds.size);
[viewToCapture.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

将视图捕捉到图像后,使用此方法缩放和淡化图像:

UIImageView *firstView = nil;

-(void)animateOut:(UIImage*)image {
    firstView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
    firstView.image = image
    [window addSubview:firstView];
    [window bringSubviewToFront:firstView];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
    firstView.alpha = 0.0;
    // change this for a different scale
    firstView.frame = CGRectMake(-60, -85, 440, 635);  
    [UIView commitAnimations];
}

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [firstView removeFromSuperview];
    [firstView release];
}

您可以从[UIApplication sharedApplication]获取窗口,或者只是将其添加为当前视图控制器视图的子视图。

相关问题