Ios 如何实现水平滚动/分页视图控制器?
正如你在我附加的截图中所看到的。我的屏幕上有两个按钮:视频和朋友 每当用户触摸按钮Ios 如何实现水平滚动/分页视图控制器?,ios,swift,Ios,Swift,正如你在我附加的截图中所看到的。我的屏幕上有两个按钮:视频和朋友 每当用户触摸按钮Videos,以下视图将向左滑动以显示视频内容。当用户触摸按钮Friends时,它将向右滑动以显示好友列表 我在上找到了关于Objective-C的教程。我一步一步地跟着,总是收到这样的错误: 'Application tried to present modally an active controller <KaptrProject.ProfileViewController: 0x7ffcb282591
Videos
,以下视图将向左滑动以显示视频内容。当用户触摸按钮Friends
时,它将向右滑动以显示好友列表
我在上找到了关于Objective-C的教程。我一步一步地跟着,总是收到这样的错误:
'Application tried to present modally an active controller <KaptrProject.ProfileViewController: 0x7ffcb2825910>.'
为什么不使用?它将提供给你什么,你正在寻找,加上其他一些页面转换动画。您可以从中找到一个很好的教程尝试使用容器视图(子视图)。
相应地添加和删除子视图控制器谢谢您的建议,Zellb。我试试看
//
// ContainerViewController.swift
// KaptrProject
//
// Created by Binh Nguyen on 5/14/15.
// Copyright (c) 2015 TrangNguyen. All rights reserved.
//
import UIKit
class ContainerViewController: UIViewController {
let SegueIdentifierFirst = "embedFirst"
let SegueIdentifierSecond = "embedSecond"
var currentSegue = ""
override func viewDidLoad() {
super.viewDidLoad()
currentSegue = SegueIdentifierFirst;
performSegueWithIdentifier(currentSegue, sender: nil)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var destVC = segue.destinationViewController as UIViewController
if segue.identifier == SegueIdentifierFirst {
if self.childViewControllers.count > 0{
var currVC = self.childViewControllers.first as UIViewController
swap(fromVC: currVC as UIViewController, toVC: destVC)
}else{
self.addChildViewController(destVC)
destVC.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
self.view.addSubview(destVC.view)
destVC.didMoveToParentViewController(self)
}
}else if segue.identifier == SegueIdentifierSecond{
var currVC = self.childViewControllers.first as UIViewController
swap(fromVC: currVC, toVC: destVC)
}
}
func swap(#fromVC:UIViewController, toVC :UIViewController){
toVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height )
fromVC.willMoveToParentViewController(nil)
addChildViewController(toVC)
transitionFromViewController(fromVC, toViewController: toVC, duration: 1.0, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: nil, completion: { finished in
fromVC.removeFromParentViewController()
toVC.didMoveToParentViewController(self)
})
}
func swapVC(){
println("swap!!!!!!!!!!!!!!!!!!!!!")
if (currentSegue == SegueIdentifierFirst){
currentSegue = SegueIdentifierSecond
}else{
currentSegue = SegueIdentifierFirst
}
performSegueWithIdentifier(currentSegue, sender: nil)
}
}