0

我试图从侧面展示一个 UIViewController。Present Modal 唯一能做的就是 Verticle Slide in。

任何机构对此有任何想法?

让我知道'谢谢

4

3 回答 3

2

我这样做了,它奏效了,虽然我不知道是否有更正式的方式来做到这一点(UIVIewAimationTransition 没有幻灯片选项):

    UIView *currentView = self.view;
UIView *theWindow = [currentView superview];

[currentView removeFromSuperview];

CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
于 2010-12-19T20:49:23.200 回答
2

对于MVC来说,它实际上是 View 你的移动,而不是控制器。

我建议这样做的方法是使用导航控制器,默认情况下它的动画是水平幻灯片,您可以免费获得一个导航堆栈 - 这意味着您有自动生成的后退按钮以及标题和按钮属性可以设置,虽然这些可以很容易地隐藏是需要的。

使用导航控制器:

在您的父控制器、syth、alloc 中创建一个 UINavigationsController 属性并适当地初始化它。然后你可以按你想要的任何顺序加载控制器,它会照顾导航。

是关于 NavControllers 的一个很好的教程(通常它们与 UITableViewControllers 一起使用,但不是必须的)

Peng 的示例是一个动画,我应该注意它删除了父视图(并且根据您的设计可能不只是删除“当前视图” - 因为您的/顶视图可能是子视图)所以如果您导航回来,您将不得不自己处理。

于 2010-12-19T20:59:59.527 回答
0

我刚刚对另一个非常相似的 SO 问题给出了这个答案,但又来了,以防人们最终看到这里。

我的应用程序中的所有 ViewControllers 都继承自MyViewController其中,除了一些其他默认行为外,还具有以下属性:

@property(readwrite, nonatomic) BOOL slideFromSide;

而这段代码:

- (void) presentViewController: (UIViewController*) vc animated: (BOOL) flag completion: (void (^)(void)) completion
{
    BOOL slideIn = NO;
    if ([vc isKindOfClass: [MyViewController class]])
    {
        MyViewController *svc = (MyViewController*) vc;
        slideIn = svc.slideFromSide;
    }

    if (slideIn)
    {
        [self addChildViewController: vc];
        [self.view addSubview: vc.view];

        CGRect frame = vc.view.frame;
        frame.origin.x = frame.size.width;
        vc.view.frame = frame;

        frame.origin.x = 0;
        [UIView animateWithDuration: 0.33
                         animations: ^{
                             vc.view.frame = frame;
                         }
         ];
    }
    else
    {
        [super presentViewController: vc animated: flag completion: completion];
    }
}


- (IBAction) backAction: (id) sender
{
    if (_slideFromSide)
    {
        CGRect frame = self.view.frame;
        frame.origin.x = frame.size.width;
        [UIView animateWithDuration: 0.33
                         animations: ^{
                             self.view.frame = frame;
                         }
                         completion:^(BOOL finished) {
                             [self removeFromParentViewController];
                         }
         ];
    }
    else
    {
        [self dismissViewControllerAnimated: YES completion: nil];
    }
}

然后,在我想要滑入的 ViewControllers 中,我有:

- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];
    if (self)
    {
        self.slideFromSide = YES;
        // Whatever else you want to do
    }

    return self;
}

调用一个新的 ViewController 就像平常一样:

WhateverViewController *vc = [WhateverViewController alloc] initWithNibName: nil bundle: nil];
[self presentViewController: vc animated: YES completion: nil];
于 2015-06-17T20:54:53.553 回答