使用destinationViewController按钮自定义SEGUE [英] Use destinationViewController button in a custom segue

查看:201
本文介绍了使用destinationViewController按钮自定义SEGUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是创建一个自定义SEGUE具有自定义动画如下:
我希望SEGUE以覆盖从sourceViewController一个按钮与从具有类似导航控制器的推作用效果的destinationViewController一个按钮,即新的按钮是应该由右至左推旧按钮远

My goal is to make a custom segue with a custom animation as follows: I want the segue to cover a button from the sourceViewController with a button from the destinationViewController with an effect similar to the navigation controller's push effect, i.e. the new button is supposed to push the old button away from right to left.

我已经能够使旧按钮(从sourceViewController)搬走根据需要:

I have been able to make the old button (from the sourceViewController) move away as desired:

[UIView animateWithDuration:1.0 animations:^{
        // set the target frame for animated view
        sourceViewController.optionsButton.frame = leftButtonTargetFrame;
    } completion:^(BOOL finished) {
        [navigationController pushViewController:destinationViewController animated:NO];
        // reset the button's frame back to its original frame
        sourceViewController.optionsButton.frame = leftButtonInitFrame;
}];

但我努力使新的按钮(从destinationViewController)中招的原因是,我无法访问destinationViewController的视图元素:在执行他们没有实例化SEGUE。我不能动画未实例化一个按钮。

But I am struggling to make the new button (from the destinationViewController) move in. The reason is that I cannot access the destinationViewController's view elements: While performing the segue they are not instantiated. And I cannot animate a button that is not instantiated.

所以,我怎么能替换sourceViewController一个按钮从destinationViewController一个按钮?

So how can I replace a button in the sourceViewController with a button from the destinationViewController?

推荐答案

目标视图控制器的观点尚未初始化/时加载,当您尝试访问的按钮。要加载目标视图控制器的观点,你可以简单地访问视图属性。使用按钮之前: [destinationViewController视图];

The view of the destination view controller hasn't been initialized/loaded at the time when you try to access the buttons. To load the view of the destination view controller, you can simply access the view property. Do this before using the buttons: [destinationViewController view];

destinationViewController.view; 也将工作,但它会产生一个编译器警告

destinationViewController.view; would also work, but it would generate a compiler warning.

背景资料:

如果您访问<一个href=\"http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/view\"相对=nofollow>视图财产,目前其价值为零,视图控制器会自动调用的loadView方法,并返回结果视图。

If you access the view property and its value is currently nil, the view controller automatically calls the loadView method and returns the resulting view.

该方法<一href=\"http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/loadView\"相对=nofollow>的loadView 加载控制器管理视图。你永远不应该直接调用此方法。

The method loadView loads the view that the controller manages. You should never call this method directly.

这篇关于使用destinationViewController按钮自定义SEGUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆