我有一个滚动视图,其中3个viewcontrollers水平滚动,其中一个viewcontrollers有3个viewcontrollers垂直滚动。访问这些viewcontrollers的唯一方法是登录。在垂直scrollview上我希望中间页面是起始页面,然后用户可以选择向上或向下滚动。现在垂直scrollview从第一页开始,但我希望它从中间页(第二页)开始。
@IBOutlet weak var scroller: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
let profile: ProfileView = self.storyboard?.instantiateViewControllerWithIdentifier("profile") as! ProfileView
let music: View2 = self.storyboard?.instantiateViewControllerWithIdentifier("View2") as! View2
let camera: Camera = self.storyboard?.instantiateViewControllerWithIdentifier("camera") as! Camera
self.addChildViewController(profile)
self.scroller.addSubview(profile.view)
profile.didMoveToParentViewController(self)
self.addChildViewController(music)
self.scroller.addSubview(music.view)
music.didMoveToParentViewController(self)
self.addChildViewController(camera)
self.scroller.addSubview(camera.view)
camera.didMoveToParentViewController(self)
var musicFrame: CGRect = profile.view.frame
musicFrame.origin.y = 2 * self.view.frame.height
music.view.frame = musicFrame
var profileFrame: CGRect = camera.view.frame
profileFrame.origin.y = self.view.frame.height
profile.view.frame = profileFrame
self.scroller.contentSize = CGSizeMake(self.view.frame.width, self.view.frame.size.height*3)
// Do any additional setup after loading the view.
}
答案 0 :(得分:1)
scrollview有一个contentoffset,你可以设置y的位置。检测中间视图的y位置并将scrollviews contentOffSet设置为
如果内存服务,您必须在viewWillAppear
中对contentOffset的更改进行动画处理(或不进行动画处理)