我怎样才能让我的视野缩小并消失?

发布于 2024-11-08 02:33:01 字数 876 浏览 0 评论 0原文

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

-(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 内容?

When my user presses a button, I want the visible view to shrink and disappear, revealing the parent view underneath. Currently I have this, which almost works:

-(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];
    }
}

There are two problems with this, however:

  • The view that does the shrinking is not the "whole" view - it does not include the title bar and toolbar.
  • The view shrinks to reveal a plain white background, and only then is the second method triggered, so the white background is unceremoniously replaced with the parent view.

Is there a way to include the whole screen and smoothly reveal the parent view controller behind, without getting into OpenGL stuff which is far too complicated for my current level of programming?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潇烟暮雨 2024-11-15 02:33:01

这应该捕获您的整个视图:

#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] 获取窗口,或者将其添加为当前视图控制器的视图的子视图。

This should capture your whole view:

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

Once your capture your view to an image, use this method to scale and fade the image:

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];
}

You can get the window from the [UIApplication sharedApplication], or just add it as a subview of the view of the current view controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文