Unable To Add Gesture on Dynamically Added UILabel - ios

I am trying to add gesture on a dynamically created label but its not working this the code but its not working.
what am i doing wrong ?
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 285)
label.textAlignment = .center
label.text = field.text
label.isZoomEnabled = true;
label.minFontSize = 10;
label.maxFontSize = 80;
label.adjustsFontSizeToFitWidth = true;
label.setNeedsLayout()
label.isUserInteractionEnabled = true
let panRecognizer = UITapGestureRecognizer(target: self, action:Selector(("handlePan:")))
let rotateRecognizer = UITapGestureRecognizer(target: self, action:Selector(("handleRotate:")))
panRecognizer.delegate = self
rotateRecognizer.delegate = self
label.addGestureRecognizer(panRecognizer)
label.addGestureRecognizer(rotateRecognizer)
self.view.addSubview(label);
self.imagePicked.addSubview(label)
#IBAction func handlePan(recognizer:UIPanGestureRecognizer) {
let translation = recognizer.translation(in: self.view)
if let view = recognizer.view {
view.center = CGPoint(x:view.center.x + translation.x,
y:view.center.y + translation.y)
}
recognizer.setTranslation(CGPoint(x:0,y:0), in: self.view)
}
#IBAction func handleRotate(recognizer : UIRotationGestureRecognizer) {
if let view = recognizer.view {
view.transform = view.transform.rotated(by: recognizer.rotation)
recognizer.rotation = 0
}
}
Thanks In Advance.

You are creating UITapGestureRecognizer but the methods were taking UIPanGestureRecognizer and UIRotationGestureRecognizer. Also changed the selector so the methods are called properly and changed IBActions to methods.
Replace your code with this and it will work fine,
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 285)
label.textAlignment = .center
label.text = field.text
label.isZoomEnabled = true;
label.minFontSize = 10;
label.maxFontSize = 80;
label.adjustsFontSizeToFitWidth = true;
label.setNeedsLayout()
label.isUserInteractionEnabled = true
let panRecognizer = UIPanGestureRecognizer(target: self, action:#selector(self.handlePan))
let rotateRecognizer = UIRotationGestureRecognizer(target: self, action:#selector(self.handleRotate))
panRecognizer.delegate = self
rotateRecognizer.delegate = self
label.addGestureRecognizer(panRecognizer)
label.addGestureRecognizer(rotateRecognizer)
self.view.addSubview(label);
self.imagePicked.addSubview(label)
func handlePan(recognizer:UIPanGestureRecognizer) {
let translation = recognizer.translation(in: self.view)
if let view = recognizer.view {
view.center = CGPoint(x:view.center.x + translation.x,
y:view.center.y + translation.y)
}
recognizer.setTranslation(CGPoint(x:0,y:0), in: self.view)
}
func handleRotate(recognizer : UIRotationGestureRecognizer) {
if let view = recognizer.view {
view.transform = view.transform.rotated(by: recognizer.rotation)
recognizer.rotation = 0
}
}

It's the problem of UIlabel's superView.
I assume the imagePicked is an instance of UIImageView, and the default value of UIImageView's isUserInteractionEnabled is flase.
So the imagePicked and all of it's subviews cannot receive touch events.
To fix this problem, enbale the isUserInteractionEnabled property of UIImageView:
self.imagePicked.isUserInteractionEnabled = true;

Related

How to create swipe to start button with moving arrows

I want to create the exactly the same swipe button like this https://github.com/shadowfaxtech/proSwipeButton .
I was wondering how to change the arrow of the button on user touches
I was doing this for getting swipe action.
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:)))
rightSwipe.direction = .right
view.addGestureRecognizer(rightSwipe)
but the thing is how to add arrows to button which change there position on user touches.
Here is the code I have written for swiping over the button. You assign image to the image view.
func createSwipeButton() {
let button = UIButton.init(type: .custom)
button.backgroundColor = UIColor.brown
button.setTitle("PLACE ORDER", for: .normal)
button.frame = CGRect.init(x: 10, y: 200, width: self.view.frame.size.width-20, height: 100)
button.addTarget(self, action: #selector(swiped(_:event:)), for: .touchDragInside)
button.addTarget(self, action: #selector(swipeEnded(_:event:)), for: .touchUpInside)
self.view.addSubview(button)
let swipableView = UIImageView.init()
swipableView.frame = CGRect.init(x: 0, y: 0, width: 20, height: button.frame.size.height)
swipableView.tag = 20
swipableView.backgroundColor = UIColor.white
button.addSubview(swipableView)
}
#objc func swiped(_ sender : UIButton, event: UIEvent) {
let swipableView = sender.viewWithTag(20)!
let centerPosition = location(event: event, subView: swipableView, superView: sender,isSwiping: true)
UIView.animate(withDuration: 0.2) {
swipableView.center = centerPosition
}
}
#objc func swipeEnded(_ sender : UIButton, event: UIEvent) {
let swipableView = sender.viewWithTag(20)!
let centerPosition = location(event: event, subView: swipableView, superView: sender, isSwiping: false)
UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: .curveEaseInOut, animations: {
swipableView.center = centerPosition
}) { _ in}
}
func location(event: UIEvent, subView: UIView, superView: UIButton, isSwiping: Bool) -> CGPoint {
if let touch = event.touches(for: superView)?.first{
let previousLocation = touch.previousLocation(in: superView)
let location = touch.location(in: superView)
let delta_x = location.x - previousLocation.x;
print(subView.center.x + delta_x)
var centerPosition = CGPoint.init(x: subView.center.x + delta_x, y: subView.center.y)
let minX = subView.frame.size.width/2
let maxX = superView.frame.size.width - subView.frame.size.width/2
centerPosition.x = centerPosition.x < minX ? minX : centerPosition.x
centerPosition.x = centerPosition.x > maxX ? maxX : centerPosition.x
if !isSwiping{
let normalPosition = superView.frame.size.width * 0.5
centerPosition.x = centerPosition.x > normalPosition ? maxX : minX
centerPosition.x = centerPosition.x <= normalPosition ? minX : centerPosition.x
}
return centerPosition
}
return CGPoint.zero
}
Complete project is on github: https://github.com/IamSaurav/SwipeButton
Mmm what about something like this?
You can add an UIImage in the storyboard in the swipeImage var.
The best effect is done if the image has the same color of the text.
import UIKit
#IBDesignable
class UISwipeableLabel: UILabel {
#IBInspectable var swipeImage: UIImage? {
didSet {
configureSwipeImage()
}
}
private var swipeImageView: UIImageView?
private var rightSwipe: UIPanGestureRecognizer?
private var shouldActivateButton = true
override func awakeFromNib() {
super.awakeFromNib()
configureSwipeImage()
clipsToBounds = true
}
}
private extension UISwipeableLabel {
#objc func handleSwipes(_ sender:UIPanGestureRecognizer) {
if let centerX = swipeImageView?.center.x {
let translation = sender.translation(in: self)
let percent = centerX/frame.width
if sender.state == .changed {
if centerX < frame.width - frame.height/2 {
swipeImageView?.center.x = centerX + translation.x
sender.setTranslation(CGPoint.zero, in: swipeImageView)
} else {
swipeImageView?.center.x = frame.width - frame.height/2
if shouldActivateButton {
activateButton()
}
}
}
if sender.state == .ended || sender.state == .cancelled || sender.state == .failed {
if shouldActivateButton {
UIView.animate(withDuration: 0.25 * TimeInterval(percent)) {
self.swipeImageView?.center.x = self.frame.height/2
}
}
}
}
}
func configureSwipeImage() {
if swipeImageView != nil {
swipeImageView?.removeFromSuperview()
}
swipeImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: frame.height, height: frame.height))
if let swipeImageView = swipeImageView {
swipeImageView.image = swipeImage
swipeImageView.isUserInteractionEnabled = true
swipeImageView.alpha = 0.5
addSubview(swipeImageView)
rightSwipe = UIPanGestureRecognizer(target: self, action: #selector(handleSwipes(_:)))
if let rightSwipe = rightSwipe {
swipeImageView.addGestureRecognizer(rightSwipe)
}
}
}
func activateButton() {
print("*** DO YOUR STUFF HERE ***")
}
}
You start with a UILabel and if you want, change it to use autolayout.

Programmatically UIPanGestureRecognizer not doing anything

I have the folling UIView with a gesture recognizer that calls a function like so:
let cardView: UIView = {
let cv = UIView()
cv.backgroundColor = .red
cv.translatesAutoresizingMaskIntoConstraints = false
cv.layer.cornerRadius = 5
cv.layer.masksToBounds = true
cv.isUserInteractionEnabled = true
cv.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(handlePan)))
return cv
}()
and the implementation of the gesture recognizer like this:
// pan functionality
func handlePan(gesture: UIPanGestureRecognizer) {
let translation = gesture.translation(in: self.view)
if let card = gesture.view {
card.center = CGPoint(x: card.center.x + translation.x, y: card.center.y + translation.y)
}
}
However, when I try to move the card in the view controller nothing happens.
Any and all help is greatly appreciated.

Drag items placed on UIStackView

I have the code below, and need to drag the views so they can be repositioned. However, on drag, the view simply disappears. How can I make the views draggable while on top of the stack view?
Stack View:
let sView = UIStackView()
sView.axis = UILayoutConstraintAxis.Vertical
sView.distribution = .FillEqually
sView.alignment = UIStackViewAlignment.Center
sView.spacing = 15
sView.backgroundColor = UIColor.redColor()
sView.addArrangedSubview(view1)
sView.addArrangedSubview(view2)
sView.addArrangedSubview(view3)
sView.layoutMarginsRelativeArrangement = true
sView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(sView)
sView.centerXAnchor.constraintEqualToAnchor(self.view.centerXAnchor).active = true
sView.centerYAnchor.constraintEqualToAnchor(self.view.centerYAnchor).active = true
The views; view1, view2, and view3 have similar code as below:
let view1 = UIView()
view1.frame = CGRectMake(30, 50, 50, 80)
view1.backgroundColor = UIColor.blueColor()
view1.layer.cornerRadius = 6
let gesture = UIPanGestureRecognizer(target: self, action: Selector("draggedView:"))
view1.addGestureRecognizer(gesture)
view1.userInteractionEnabled = true
view1.tag = 1
view1.heightAnchor.constraintEqualToConstant(85).active = true
view1.widthAnchor.constraintEqualToConstant(55).active = true
The draggedView function:
func draggedView(gesture: UIPanGestureRecognizer){
let loc = gesture.locationInView(self.view)
let gesturedView = gesture.view
gesturedView!.center = loc
}
Brian,
This code does what I think your looking to do. Obviously you need to go thru it carefully and change variable names, but I sure you up to it!
func draggedView(sender: UIPanGestureRecognizer) {
if (sender.state == UIGestureRecognizerState.Began) {
self.source = editorSVB!.arrangedSubviews.indexOf(sender.view!)! as Int
}
if (sender.state == UIGestureRecognizerState.Changed) {
center = sender.view?.center
let translation = sender.translationInView(sender.view)
center = CGPointMake(center!.x + translation.x, center!.y + translation.y)
sender.view?.center = center!
sender .setTranslation(CGPointZero, inView: sender.view)
}
for blah in self.editorSVB!.arrangedSubviews {
let no = blah.frame.intersect((sender.view?.frame)!)
if (!no.origin.x.isInfinite) {
self.object = editorSVB!.arrangedSubviews.indexOf(blah)! as Int
if (self.object != self.source) {
print("self,object, self.object",self,object, self.source)
self.executable = self.object
}
}
}
}

How to go back to main scene when my game paused in sprite kit

When I pause my game I have a pause scene.
I put there 3 buttons :
RateApp button
BackToMain button.
ResumeGame button.
what happens:
RateApp button working.
ResumeGame button working.
Not working :
BackToMain button.
Why?
because my game still pause.
PauseGame function
func pauseGame() {
isPause = true
self.view?.paused = true
pointsLabel.hidden = true
BooCharacter.hidden = true
PauseButton.hidden = true
if #available(iOS 9, *) {
RecordButton.hidden = true
}
PauseScreen = SKSpriteNode()
PauseScreen.name = "PauseScreen"
PauseScreen.position = CGPointMake(self.size.width/2, self.size.height/2)
PauseScreen.color = UIColor.blackColor()
PauseScreen.alpha = 0.9
PauseScreen.size = CGSizeMake(1242,2208)
addChild(PauseScreen)
PauseLable.text = "Pause"
PauseLable.fontSize = 75
PauseLable.fontName = "Futura-Medium"
PauseLable.fontColor = UIColor(red:0.98, green:0.82, blue:0.32, alpha:1.0)
PauseLable.position = CGPoint(x: self.size.width/2, y: self.size.height/2 + 170)
addChild(PauseLable)
ContinueButton.name = "CountinueButton"
ContinueButton.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
ContinueButton.size = CGSizeMake(100, 100)
addChild(ContinueButton)
HomeButton.position = CGPoint(x: self.size.width/2 - 50, y: self.size.height/2 - 200)
HomeButton.size = CGSizeMake(70 , 70)
HomeButton.name = "HomeButton"
HomeButton.runAction(SKAction.moveToY(90, duration: 0.6))
HomeButton.removeFromParent()
addChild(HomeButton)
RateButton.position = CGPoint(x: self.size.width/2 + 50, y: self.size.height/2 - 200)
RateButton.size = CGSizeMake(70 , 70)
RateButton.name = "RateButton"
RateButton.runAction(SKAction.moveToY(90, duration: 0.6))
RateButton.removeFromParent()
addChild(RateButton)
}
Updated :
let scene = GameScene(fileNamed:"GameScene")
var HomeButton : UIButton!
var RateButton : UIButton!
override func viewDidLoad() {
super.viewDidLoad()
if (scene != nil) {
// Configure the view.
let skView = self.view as! SKView
//skView.showsFPS = true
//skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
//skView.showsPhysics = true
NSNotificationCenter.defaultCenter().addObserver(self, selector: "goBack", name: "goBackClick", object: nil);
/* Set the scale mode to scale to fit the window */
scene!.scaleMode = .AspectFill
skView.presentScene(scene)
}
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
HomeButton.frame = CGRectMake(self.view!.frame.size.width/2 - 50, self.view!.frame.size.height/2 - 200, 70, 70)
HomeButton.setImage(UIImage(named: "HomeButtonPause.png"), forState: UIControlState.Normal)
HomeButton.addTarget(self, action: "pressedHomeButton", forControlEvents: .TouchUpInside)
RateButton.frame = CGRectMake(self.view!.frame.size.width/2 + 50, self.view!.frame.size.height/2 - 200, 70, 70)
RateButton.setImage(UIImage(named: "RateButtonPause.png"), forState: UIControlState.Normal)
RateButton.addTarget(self, action: "pressedRateButton", forControlEvents: .TouchUpInside)
self.view.addSubview(HomeButton)
self.view.addSubview(RateButton)
}
func pressedHomeButton(sender: UIButton!) {
//Back to main screen
SKTAudio.sharedInstance().playSoundEffect("Click Button Sound.mp3");
NSNotificationCenter.defaultCenter().removeObserver(self, name: "goBackClick", object: nil)
self.dismissViewControllerAnimated(true, completion: {
});
}
func pressedRateButton(sender: UIButton!) {
//Rate App
SKTAudio.sharedInstance().playSoundEffect("Click Button Sound.mp3");
UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/us/app/boo-adventure/id1030047247?ls=1&mt=8")!) //add your link here
print("Rate App!")
}
i trying to create 2 subviews for my 2 button (Home Button , Rate Button)
and i created UIButtons for them but Xcode return error!
PauseGame function Updated!
func pauseGame() {
isPause = true
GameViewController().ContinueGame()
pointsLabel.hidden = true
BooCharacter.hidden = true
PauseButton.hidden = true
if #available(iOS 9, *) {
RecordButton.hidden = true
}
PauseScreen = SKSpriteNode()
PauseScreen.name = "PauseScreen"
PauseScreen.position = CGPointMake(self.size.width/2, self.size.height/2)
PauseScreen.color = UIColor.blackColor()
PauseScreen.alpha = 0.9
PauseScreen.size = CGSizeMake(1242,2208)
addChild(PauseScreen)
PauseLable.text = "Pause"
PauseLable.fontSize = 75
PauseLable.fontName = "Futura-Medium"
PauseLable.fontColor = UIColor(red:0.98, green:0.82, blue:0.32, alpha:1.0)
PauseLable.position = CGPoint(x: self.size.width/2, y: self.size.height/2 + 170)
addChild(PauseLable)
ContinueButton.name = "CountinueButton"
ContinueButton.position = CGPoint(x: self.size.width/2, y: self.size.height/2)
ContinueButton.size = CGSizeMake(100, 100)
addChild(ContinueButton)
GameViewController().viewWillLayoutSubviews()
}
Try this to take you back to the beginning of your GameScene
func goToGameScene(){
let gameScene:GameScene = GameScene(size: self.view!.bounds.size) // create your new scene
let transition = SKTransition.fadeWithDuration(1.0) // create type of transition (you can check in documentation for more transtions)
gameScene.scaleMode = SKSceneScaleMode.Fill
self.view!.presentScene(gameScene, transition: transition)
}
if this doesn't work let me know.

Find sender's tag with gesture recognizer and swift

tl;dr : how should I set my tags so that they can be retrieved with the gesture recognizer ?
I'm setting a view in which the user can spawn multiple UIImageViews when he presses a button.
The image creation process is :
var siegeView: UIView!
var round1: UIImageView!
var setTag : Int!
var tagCounter = 0
#IBAction func showContent(sender: AnyObject) {
round1 = UIImageView(frame: CGRectMake(0, 0, 100, 100))
round1.image = UIImage(named: nomDuRond.text)
setTag = tagCounter
tagCounter++
self.rond1.tag = setTag
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.center = CGPointMake(round1.frame.origin.x+50, round1.frame.origin.y+100)
label.textAlignment = NSTextAlignment.Center
label.text = nomDuRond.text
siegeView = UIView(frame: CGRectMake(round1.frame.origin.x, round1.frame.origin.y, round1.frame.size.width, round1.frame.size.height))
round1.userInteractionEnabled = true
siegeView.addSubview(rond1)
siegeView.addSubview(label)
view.addSubview(siegeView)
let recognizer = UIPanGestureRecognizer(target: self, action:Selector("handlePan:"))
recognizer.delegate = ClassSiege()
siegeView.addGestureRecognizer(recognizer)
Then the user can move the created images using the Gesture Recognizer's fonction "handlePan" below :
func handlePan(recognizer:UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.view)
self.view.bringSubviewToFront(recognizer.view!)
recognizer.view!.center = CGPoint(x:recognizer.view!.center.x + translation.x,
y:recognizer.view!.center.y + translation.y)
recognizer.setTranslation(CGPointZero, inView: self.view)
var centerBoardX = BlackBoard.center.x
var centerBoardY = BlackBoard.center.y
var centerRondX = round1.superview?.center.x
var centerRondY = round1.superview?.center.y
var switchRang = premierRang
DistanceCenterY.text = " \(centerRondY! - centerBoardY)"
if centerRondY! - centerBoardY < 100 {
switchRang.setOn(true, animated: true)
println("dans switch if")
} else {
switchRang.setOn(false, animated: true)
println("dans switch else")
}
}
My goal, for now, is to be able to get the DistanceCenterY information, and the if operation to be active for each view the user is moving. But it's only working for the last view created.
My guess is that it can work if I specify the image's tag.
But I can't figure out how to retrieve the tag of the image that is currently being moved by the user.
I tried this solution here, but it's not the image's tag as it always returns 0 even if the tag is different.
So, my question is : how should I set my tags so that they can be retrieved with the gesture recognizer ?
I'm deeply stuck here, so any help would be greatly appreciated !
Thanks
Update 1 :
Thanks to Rdelmar, I've been able to move forward... but not too far !
I updated the way I create the image, and modified the Gesture Recognizer fonction to use the tag info to get the info of which image is selected.
The code is :
var siegeView: UIView!
var rond1: UIImageView!
var rond2: UIImageView!
var setTag : Int!
var tagCounter = 1
var tagInfo = 0
func handlePan(recognizer:UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.view)
recognizer.view!.center = CGPoint(x:recognizer.view!.center.x + translation.x,
y:recognizer.view!.center.y + translation.y)
recognizer.setTranslation(CGPointZero, inView: self.view)
var switchRang = premierRang
//Here I'm getting the tag from the recognizer.
var tag = recognizer.view?.tag
tagInfo = tag!
var centerBoardX = BlackBoard.center.x
var centerBoardY = BlackBoard.center.y
//to get the coordinates of the image, i'm getting the info using the tag I got earlier.
var centerRondX = rond1.viewWithTag(tagInfo)!.center.x
var centerRondY = rond1.viewWithTag(tagInfo)!.center.y
DistanceCenterY.text = " \(centerRondY - centerBoardY)"
if centerRondY - centerBoardY < 100 {
switchRang.setOn(true, animated: true)
println("dans switch if")
} else {
switchRang.setOn(false, animated: true)
println("dans switch else")
}
}
and the showcontent fonction updated :
#IBAction func showContent(sender: AnyObject) {
rond1 = UIImageView(frame: CGRectMake(0, 0, 100, 100))
rond1.image = UIImage(named: nomDuRond.text)
setTag = tagCounter
tagCounter++
rond1.tag = setTag
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.center = CGPointMake(rond1.frame.origin.x+50, rond1.frame.origin.y+100)
label.textAlignment = NSTextAlignment.Center
label.text = nomDuRond.text
rond1.userInteractionEnabled = true
view.addSubview(rond1)
//the label subview was getting me some bugs, so for now I removed it.
//view.addSubview(label)
let recognizer = UIPanGestureRecognizer(target: self, action:Selector("handlePan:"))
recognizer.delegate = ClassSiege()
rond1.addGestureRecognizer(recognizer)
The tag returned is correct when I move the image, but when I adding a second image and I'm moving the first one, I get a fatal error because a nil was returned for the line var centerRondY = rond1.viewWithTag(tagInfo)!.center.y
I'm still stuck because I can't find what's wrong. It's not clear to me how the recognizer is working. If you have some clues, it's still very very much appreciated. Thanks !
I think this code does what you want. I commented some stuff out, since I didn't know what it was, and I hard coded the image and text in the label. As I said in my comment, you don't need to use tags, since each recognizer knows its own view. I commented out the button stuff, but I do see the "if" and "else" log statements fire as I move the views up and down the screen,
class ViewController: UIViewController {
#IBAction func showContent(sender: AnyObject) {
var rond1 = UIImageView(frame: CGRectMake(0, 0, 100, 100))
rond1.image = UIImage(named:"Lofoten.jpg")
var label = UILabel(frame: CGRectMake(0, 0, 200, 21))
label.center = CGPointMake(rond1.frame.origin.x+50, rond1.frame.origin.y+100)
label.textAlignment = NSTextAlignment.Center
label.text = "Picture"
label.textColor = UIColor.whiteColor()
label.frame = CGRectMake(0, rond1.frame.size.height - 25, 100, 25)
rond1.addSubview(label)
rond1.userInteractionEnabled = true
view.addSubview(rond1)
let recognizer = UIPanGestureRecognizer(target: self, action:Selector("handlePan:"))
rond1.addGestureRecognizer(recognizer)
}
func handlePan(recognizer:UIPanGestureRecognizer) {
let iv = recognizer.view
let translation = recognizer.translationInView(self.view)
iv.center.x += translation.x
iv.center.y += translation.y
recognizer.setTranslation(CGPointZero, inView: self.view)
// var switchRang = premierRang
var centerBoardY = self.view.center.y
var centerRondY = iv.center.y
//DistanceCenterY.text = " \(centerRondY - centerBoardY)"
if centerRondY - centerBoardY < 100 {
//switchRang.setOn(true, animated: true)
println("dans switch if")
} else {
//switchRang.setOn(false, animated: true)
println("dans switch else")
}
}
}

Resources