0

我有一个按钮,当按下它时,会添加一个带有其他按钮的新子视图。我已经这样做了。

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 modal 样式对新视图进行动画处理。我怎样才能以编程方式做到这一点?

4

3 回答 3

3

你可以这样做performSegueWithIdentifier,这里是代码

- (void)newView
{
    //execute segue programmatically
    [self performSegueWithIdentifier: @"MySegue" sender: self];
}
于 2013-05-20T11:38:33.983 回答
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
      }];

}
于 2013-05-20T11:52:47.613 回答
0

你可以像这样展示一个新的视图控制器:

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

希望能帮助到你!:)

于 2013-05-20T12:01:20.420 回答