iPhone 中类之间转换的卷页效果

发布于 2024-11-16 20:01:05 字数 754 浏览 4 评论 0原文

我正在使用页面卷曲效果。单击按钮后,我能够转换页面(即在 UIView 之间)。以下代码描述了

UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.5];  
    if ([sender tag] == 1) {
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:placeholder cache:YES];
    }
    else {
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:placeholder cache:YES];
    }
    if (view1OnTop) {
        [view1 removeFromSuperview];
        [placeholder addSubview:view2];
    }
    else {
        [view2 removeFromSuperview];
        [placeholder addSubview:view1];
    }
    [UIView commitAnimations];

    view1OnTop = !view1OnTop;

与此相同的内容,我能够在 UIView 之间卷曲,但我的问题是,我会吗能够在两个或多个类之间应用这种转换??? 提前致谢

i am working with page curling effect .on click of a button i was able to transit the page(i.e between the UIViews).the following code depicts the same

UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.5];  
    if ([sender tag] == 1) {
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:placeholder cache:YES];
    }
    else {
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:placeholder cache:YES];
    }
    if (view1OnTop) {
        [view1 removeFromSuperview];
        [placeholder addSubview:view2];
    }
    else {
        [view2 removeFromSuperview];
        [placeholder addSubview:view1];
    }
    [UIView commitAnimations];

    view1OnTop = !view1OnTop;

with this i was able to curl between UIViews ,but my question is , will i be able to apply this kind of transition between two or more classes???
thanks in advance

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

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

发布评论

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

评论(1

初与友歌 2024-11-23 20:01:05

并非所有东西都可以动画化。只有 UIKit 的一部分是。因此,如果您想问 NSObject 的任何子类是否可以动画,那么它们不能。如果您想问 UIView 的子类是否可以动画,那么答案是肯定的。它们也可以是不同的子类。虽然这是可能的,但这并不意味着它会给我们正确的结果。他们最终可能看起来很奇怪。你可能不想这样做。

图层也可以设置动画。

然而,这一切都取决于你所说的类的含义。

动画到新的视图控制器

假设您想改变在视图控制器之间切换的方式,可以使用 UIView< 的 transitionWithView:duration:.. 类方法/代码>。例如,

SecondViewController * viewController = [[[SecondViewController alloc] initWithNibName:nil bundle:nil] autorelease];
[UIView transitionWithView:self.view.window
                  duration:1.0f
                   options:UIViewAnimationOptionTransitionCurlUp
                animations:^{
                    [self.navigationController pushViewController:viewController animated:NO];
                }
                completion:NULL];

这将在推送新视图控制器时使用卷曲过渡。

对于 4.0 之前的 iOS 版本

由于它们不支持基于块的动画 API,因此您必须这样做,

[UIView beginAnimations:@"Curl up" context:NULL];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view.window cache:YES];

[self.navigationController pushViewController:viewController animated:NO];

[UIView commitAnimations];

Not everything is animatable. Only parts of UIKit are. So if you mean to ask if any subclass of NSObject can be animated then no they can't. If you mean to ask if whether subclasses of UIView can be animated then the answer would be yes. They can be different subclasses too. While this is possible, it doesn't mean it will give us the right results. They might end up looking pretty weird. You might not want to do that.

Layers are animatable too.

However it all depends on what you mean by classes.

Animating to a new view controller

Say you want to alter the way you shift between view controllers, you can use transitionWithView:duration:.. class method of UIView. An example,

SecondViewController * viewController = [[[SecondViewController alloc] initWithNibName:nil bundle:nil] autorelease];
[UIView transitionWithView:self.view.window
                  duration:1.0f
                   options:UIViewAnimationOptionTransitionCurlUp
                animations:^{
                    [self.navigationController pushViewController:viewController animated:NO];
                }
                completion:NULL];

This will use the curl up transition when pushing the new view controller.

For iOS versions older than 4.0

Since they don't support block based animation APIs, you will have to do this,

[UIView beginAnimations:@"Curl up" context:NULL];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view.window cache:YES];

[self.navigationController pushViewController:viewController animated:NO];

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