我试图设计一个包含滑动部分的屏幕.我有一个带有一个imageview的屏幕,底部有两个按钮.我想只滑动imageview而不是底部区域.屏幕是这样的
目前问题是整个屏幕也包括按钮.
这是我的代码
ViewController.swift
import UIKit class ViewController: UIViewController, UIPageViewControllerDataSource { var pageImages:NSArray! var pageViewController:UIPageViewController! override func viewDidLoad() { super.viewDidLoad() pageImages = NSArray(objects: "startscreen1","startscreen2","startscreen3") self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("MyPageViewController") as! UIPageViewController self.pageViewController.dataSource = self let initialContenViewController = self.pageTutorialAtIndex(0) as TutorialScreenViewController let viewControllers = NSArray(object: initialContenViewController) self.pageViewController.setViewControllers(viewControllers as! [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil) /* self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)*/ self.pageViewController.view.frame = CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height-100) self.addChildViewController(self.pageViewController) self.view.addSubview(self.pageViewController.view) self.pageViewController.didMoveToParentViewController(self) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func pageTutorialAtIndex(index: Int) -> TutorialScreenViewController { let pageContentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("TutorialScreenViewController") as! TutorialScreenViewController pageContentViewController.imageFileName = pageImages[index] as! String pageContentViewController.pageIndex = index return pageContentViewController } func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? { let viewController = viewController as! TutorialScreenViewController var index = viewController.pageIndex as Int if(index == 0 || index == NSNotFound) { return nil } index-- return self.pageTutorialAtIndex(index) } func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? { let viewController = viewController as! TutorialScreenViewController var index = viewController.pageIndex as Int if((index == NSNotFound)) { return nil } index++ if(index == pageImages.count) { return nil } return self.pageTutorialAtIndex(index) } func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int { return pageImages.count } func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int // The selected item reflected in the page indicator. { return 0 } }
TutorialScreenViewController.swift
@IBOutlet weak var myImageView: UIImageView! var imageFileName: String! var pageIndex:Int! var width:CGFloat! @IBOutlet weak var loginButton: UIButton! @IBOutlet weak var registerButton: UIButton! override func viewDidLoad() { super.viewDidLoad() myImageView.image = UIImage(named:imageFileName) }
Rob.. 12
您可以使用视图控制器包含:
创建一个标准视图控制器,它具有两个按钮和"容器"视图.只需在"界面"构建器的右侧面板上的对象库中搜索"容器",然后将其拖到主视图控制器的场景中:
显然,设置约束以便使用按钮正确布置此容器视图.
现在control- 从容器视图拖动到页面视图控制器,然后选择"嵌入"segue.
你最终会得到一个看起来像这样的场景:
现在,您可以在标准视图控制器中使用其他按钮欣赏页面视图控制器功能.
您可以使用视图控制器包含:
创建一个标准视图控制器,它具有两个按钮和"容器"视图.只需在"界面"构建器的右侧面板上的对象库中搜索"容器",然后将其拖到主视图控制器的场景中:
显然,设置约束以便使用按钮正确布置此容器视图.
现在control- 从容器视图拖动到页面视图控制器,然后选择"嵌入"segue.
你最终会得到一个看起来像这样的场景:
现在,您可以在标准视图控制器中使用其他按钮欣赏页面视图控制器功能.