以编程方式进行模态推送segue - Objective-c

时间:2013-05-20 11:32:54

标签: ios objective-c cocoa-touch

我有一个按钮,当按下该按钮时,会在其上添加一个新的子视图和其他按钮。我这样做了。

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget: @selector(newView)];


- (void)newView
{
    UIView *newView = [[UIView alloc]initWithFrame:CGRectmake(0,0,100,100)];
    [self.view addSubview:newView];
}

现在按下按钮时,只会添加新视图。我希望像在IB中一样使用push segue模式样式为新视图制作动画。我怎么能以编程方式做到这一点?

3 个答案:

答案 0 :(得分:3)

您可以使用performSegueWithIdentifier执行此操作,此处是代码

- (void)newView
{
    //execute segue programmatically
    [self performSegueWithIdentifier: @"MySegue" sender: self];
}

答案 1 :(得分:0)

尝试这样的事情。

- (void)newView
{

     [self.view addSubview:newView]
      newView.frame = // somewhere offscreen, in the direction you want it to appear    from
      [UIView animateWithDuration:10.0 
                 animations:^{
                     newView.frame = // its final location
      }];

}

答案 2 :(得分:0)

你可以像这样展示一个新的viewcontroller:

- (void)newView
{
     //Embed your new View into a plain UIViewController
     UIView *newView = [[UIView alloc]initWithFrame:CGRectmake(0,0,100,100)];
     UIViewController *yourNewViewController= [[UIViewController alloc] init];
     controller.view = newView;

    //Present it animated         
    [self presentViewController:yourNewViewController animated:YES completion:nil];
}

希望它有所帮助! :)