我试图设计一个包含滑动部分的屏幕。我有一个带有一个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)
}