2

我正在尝试将容器内的嵌入内容从 tableviewcontroller 更改为地图。我试过搜索它,但所有问题都与 tabview 有关,我没有这样做。我将如何开始这个过程?

我也试过

- (IBAction)changer:(id)sender {
    UIViewController *viewController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"vc1"];
    container.view = viewController1;
}

但这不起作用

4

2 回答 2

5

尝试

MyViewController *viewController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"vc1"];
viewController1.view.frame = self.container.bounds;

[viewController1 willMoveToParentViewController:self];
[self.container addSubview:viewController1.view];
[self addChildViewController:viewController1];
[viewController1 didMoveToParentViewController:self];
于 2013-06-14T05:17:45.710 回答
0

这是我在 Swift 中的实现:

func navigateTo(vc: NSViewController){
    vc.view.frame = self.containerView.bounds;
    if let currentSubview = containerView.subviews.first {
        self.containerView.replaceSubview(currentSubview, with: vc.view)
    } else {
        self.containerView.addSubview(vc.view)
    }
    self.addChildViewController( vc )
}

对于动画过渡,我实现了 awakeFromNib

override func awakeFromNib() {
    let animation: CATransition = CATransition()
    animation.type = kCATransitionMoveIn
    animation.subtype = kCATransitionFromRight
    animation.duration = 0.75
    animation.delegate = self
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    if let _ = containerView {
        containerView.wantsLayer = true
        containerView.animations = NSDictionary(object: animation, forKey: "subviews") as! [String : AnyObject]
    }
}

并将self.containerView.replaceSubview行替换为:

self.containerView.animator().replaceSubview(currentSubview, with: vc.view)
于 2015-09-30T09:12:25.833 回答