ios - how reference storyboard (current view) from another normal class -
i create animation in class (outside of normal view) called viewdidload
method , make run on storyboard :
how connect class effect class viewcontroller
(storyboard) ??
class viewcontroller : uiviewcontroller { var effetto:effects = effects() override func viewdidload() { super.viewdidload() effects.typeeffects = 1 effects.createeffect } } class effects { var squareview: uiview! var gravity: uigravitybehavior! var animator: uidynamicanimator! var collision: uicollisionbehavior! var typeeffects = 0 func createeffect() { if var typeeffect = 1){ gravity() } else { other() } } func gravity() { squareview = uiview(frame: cgrect(x: 100, y: 100, width: 100, height: 100)) squareview.backgroundcolor = uicolor.bluecolor() viewcontroller.addsubview(squareview) animator = uidynamicanimator(referenceview: viewcontrolle) gravity = uigravitybehavior(items: [squareview]) animator.addbehavior(gravity) collision = uicollisionbehavior(items: [squareview]) collision.translatesreferenceboundsintoboundary = true // collision.addboundarywithidentifier("barrier", frompoint: cgpointmake(self.view.frame.origin.x, 350), topoint: cgpointmake(self.view.frame.origin.x + self.view.frame.width, 350)) animator.addbehavior(collision) } func other() { ...... } }
in short, dont hook non-subclass object in storyboard. uiviewcontroller's class name non-descriptive still work , contains instance of effects class. on viewdidload creating instance of class. type in viewcontroller class name in identity inspector in ib. otherwise name more descriptive such following add effectsviewcontroller in identity inspector if it's confusing. following should work(not tested , shown purely show object passing)
class effectsviewcontroller : uiviewcontroller { var effects:effects = effects() override func viewdidload() { super.viewdidload() effects.effectsviewcontroller = self effects.typeeffects = 1 effects.createeffect } } class effects { var effectsviewcontroller: effectsviewcontroller! var squareview: uiview! var gravity: uigravitybehavior! var animator: uidynamicanimator! var collision: uicollisionbehavior! var typeeffects = 0 func createeffect() { if var typeeffect = 1){ gravity() } else { other() } } func gravity() { squareview = uiview(frame: cgrect(x: 100, y: 100, width: 100, height: 100)) squareview.backgroundcolor = uicolor.bluecolor() effectsviewcontroller.addsubview(squareview) animator = uidynamicanimator(referenceview: viewcontrolle) gravity = uigravitybehavior(items: [squareview]) animator.addbehavior(gravity) collision = uicollisionbehavior(items: [squareview]) collision.translatesreferenceboundsintoboundary = true // collision.addboundarywithidentifier("barrier", frompoint: cgpointmake(self.view.frame.origin.x, 350), topoint: cgpointmake(self.view.frame.origin.x + self.view.frame.width, 350)) animator.addbehavior(collision) } func other() { ...... } }
Comments
Post a Comment