Three20 TTLlauncher 动画/过渡

发布于 2024-11-26 17:40:23 字数 136 浏览 1 评论 0原文

我目前使用 Three20 TTLauncher 作为我的应用程序的基础。

然而,当点击 TTLaunchItem 时,它会跳转到映射的 URL。

有什么方法可以使用 facebook 应用程序使用的相同“扩展”动画/过渡吗?

I'm currently using the Three20 TTLauncher as a base for my app.

However when tapping on a TTLaunchItem, it jumps to the mapped URL.

Is there any way that I can use the same "expanding" animation/Transition that the facebook app uses?

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

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

发布评论

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

评论(2

逆夏时光 2024-12-03 17:40:23

我假设您在 TTLauncherView 中打开 URL,如下所示:

- (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item 
{
    [[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:item.URL] applyAnimated:YES]];
}

要打开带有动画的 url,您必须为视图设置动画,然后打开 URL,如下所示。

首先,您需要一个新变量来保存您的 URL。转到您的 LauncherView.h 文件并定义一个新的 NSString *_urlToOpen;

回到您的 .m 文件,我们还需要另外 2 个方法。一个用于动画部分(仅对视图进行动画处理),另一个用于动画完成时调用。

我先发布动画的代码,稍后再解释。

-(void)animateTransition:(NSNumber *)duration {
    self.view.userInteractionEnabled=NO;
    viewController = [[[TTNavigator navigator] viewControllerForURL:_urlToOpen] retain];
    [[self view] addSubview:viewController.view];
    viewController.view.frame=[[UIScreen mainScreen] bounds];
    viewController.view.transform=CGAffineTransformMakeScale(0.01, 0.01);
    viewController.view.hidden=false;

    [UIView beginAnimations:@"animationExpand" context:NULL];
    [UIView setAnimationDuration:[duration floatValue]];
    viewController.view.transform=CGAffineTransformMakeScale(1, 1);

    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView commitAnimations];
}

首先,我们将 userInteractionEnabled 设置为 NO,以便用户在动画运行时无法点击任何按钮。然后我们从 TTNavigator 获取要打开动画的 viewController 并将其添加到实际视图(启动器视图)中。
将新视图的框架定义到屏幕边界,并将其缩小到屏幕中间的一个非常小的尺寸。现在我们设置动画以将视图缩放到其原始大小(屏幕边界)并使用 DidStopSelector 启动动画。

DidStopSelector 看起来像这样:

-(void)animationDidStop:(NSString *)animationID finished:(BOOL)finished context:(void *)context{
    self.view.userInteractionEnabled=YES;
    viewController.view.hidden=true;
    [viewController.view removeFromSuperview];
    [viewController release];
    [[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:_urlToOpen] applyAnimated:NO]];
}

第一行是不言自明的。然后我们只从超级视图中删除视图并打开我们的 URL,但没有任何过渡动画。

最后编辑您的 - (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item 方法以将 URL 保存在新变量中并调用 animateTransition 方法。

- (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item 
{
    _urlToOpen = [NSString stringWithString:item.URL];
    [self performSelector:@selector(animateTransition:) withObject:[NSNumber numberWithFloat: 0.60f]];  
}

另一个方向也是如此,但您必须关心如果用户点击导航栏上的后退按钮会发生什么。正常行为是使用标准幻灯片动画恢复动画。

此答案基于 Three20 Google Groups 的论坛主题。请在此处找到它。

I assume you are opening your URL in your TTLauncherView like this:

- (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item 
{
    [[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:item.URL] applyAnimated:YES]];
}

To open a url with a animation you have to animate the view in and then open the URL like the following.

First you need a new variable to hold your URL. Go to your LauncherView.h file and define a new NSString *_urlToOpen;

Back in your .m file we need 2 more methods. One for the animation part (just animating the view in) and another one, which gets called, when the animation has finished.

I post the code for the animation first and explain it later on.

-(void)animateTransition:(NSNumber *)duration {
    self.view.userInteractionEnabled=NO;
    viewController = [[[TTNavigator navigator] viewControllerForURL:_urlToOpen] retain];
    [[self view] addSubview:viewController.view];
    viewController.view.frame=[[UIScreen mainScreen] bounds];
    viewController.view.transform=CGAffineTransformMakeScale(0.01, 0.01);
    viewController.view.hidden=false;

    [UIView beginAnimations:@"animationExpand" context:NULL];
    [UIView setAnimationDuration:[duration floatValue]];
    viewController.view.transform=CGAffineTransformMakeScale(1, 1);

    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView commitAnimations];
}

First we set userInteractionEnabled to NO so the user is not able to tap any buttons while the animation runs. Then we get the viewController we want to open animated from the TTNavigator and add this to the actual view (the Launcher View).
Define the frame of our new view to the screen bounds and scale it down to a very small size in the middle of the screen. Now we set up the animation to scale the view up to its original size (the screen bounds) and start the animation with a DidStopSelector.

The DidStopSelector looks like this:

-(void)animationDidStop:(NSString *)animationID finished:(BOOL)finished context:(void *)context{
    self.view.userInteractionEnabled=YES;
    viewController.view.hidden=true;
    [viewController.view removeFromSuperview];
    [viewController release];
    [[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:_urlToOpen] applyAnimated:NO]];
}

The first line is self-explanatory. Then we only remove the view from the superview and open our URL but without any transition animation.

Finally edit your - (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item method to save the URL in your new variable and the call the animateTransition method.

- (void)launcherView:(TTLauncherView*)launcher didSelectItem:(TTLauncherItem*)item 
{
    _urlToOpen = [NSString stringWithString:item.URL];
    [self performSelector:@selector(animateTransition:) withObject:[NSNumber numberWithFloat: 0.60f]];  
}

The same works in the other direction, but you have to care about what happens if your user taps the back button on your navigation bar. Normal behavior is to animate back with the standard slide animation.

This answer is based on a forum thread over at the Three20 Google Groups. Find it here.

望喜 2024-12-03 17:40:23

我必须在我的一个项目中写一些类似的东西。

参见 https://github.com/aporat/TTLauncherView_ExpandViewTransitions

这个示例项目还包含了返回时的缩小效果到启动器视图& Facebook 启动器后退按钮

I had to write something similar in one of my projects.

See https://github.com/aporat/TTLauncherView_ExpandViewTransitions

This sample project also includes the shrinking effect when going back to the launcher view & the Facebook launcher back button

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