I want to scrolling view when navigationItem clicked. But..here is some error.
-
I want to make snapchatlike scroll view. It works fine, but... when I call scrollView out of viewdidload function, scrollView is nil!
-
I already make snapchat like swipe view. but I want to make swipe view when navigation Item(heart mark) clicked.
My ViewController viewdidload func - it works fine
@IBOutlet weak var scrollView: UIScrollView!
var V1 : LeftViewController = LeftViewController(nibName: "LeftViewController", bundle: nil)
var V2 : CenterViewController = CenterViewController(nibName: "CenterViewController", bundle: nil)
var V3 : RightViewController = RightViewController(nibName: "RightViewController", bundle: nil)
override func viewDidLoad() {
super.viewDidLoad()
self.addChildViewController(V1)
self.scrollView.addSubview(V1.view)
V1.didMoveToParentViewController(self)
self.addChildViewController(V2)
self.scrollView.addSubview(V2.view)
V2.didMoveToParentViewController(self)
self.addChildViewController(V3)
self.scrollView.addSubview(V3.view)
V3.didMoveToParentViewController(self)
var V2Frame : CGRect = V2.view.frame
V2Frame.origin.x = self.view.frame.width
V2.view.frame = V2Frame
var V3Frame : CGRect = V3.view.frame
V3Frame.origin.x = 2 * self.view.frame.width
V3.view.frame = V3Frame
println(self)
println(scrollView)
println(V2.view.frame)
self.scrollView.setContentOffset(CGPointMake(V2Frame.origin.x, self.view.frame.size.height), animated: false)
self.scrollView.contentSize = CGSizeMake(self.view.frame.width * 3, self.view.frame.size.height) }
My ViewController clickEvent func - why scrollView is nil?
func clickEvent() {
V2.view.frame = CGRect(x: 375.0, y: 0.0, width: 320.0, height: 568.0)
let scrollView = UIScrollView(frame: CGRect(x: 0.0, y: 0.0, width: 320.0, height: 568.0))
self.scrollView?.scrollRectToVisible(V2.view.frame, animated: true)
println(self)
println(scrollView)
println(V2.view.frame)
//self.scrollView.setContentOffset(CGPointMake(V2.view.frame.origin.x, self.view.frame.size.height), animated: true)
}
I call clickEvent in Viewcontroller from other CenterViewController - it can call fine but...in ViewController clickEvent functions' scrollView is nil.. How can I fix it?
func clickEvent(sender: AnyObject) {
ViewController().clickEvent()
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire