Add sliding label. Closes #3

This commit is contained in:
Gunay Mert Karadogan 2015-07-03 16:24:31 +02:00
parent e87e41653d
commit c4bdefb5d0
2 changed files with 27 additions and 1 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>

View File

@ -93,6 +93,9 @@ import UIKit
}
}
private let labelSlideLength: CGFloat = 5
private let labelSlideDuration: NSTimeInterval = 0.1
private let leftButton = UIButton()
private let rightButton = UIButton()
private let label = UILabel()
@ -129,6 +132,7 @@ import UIKit
label.font = labelFont
addSubview(label)
backgroundColor = buttonsBackgroundColor
layer.cornerRadius = cornerRadius
clipsToBounds = true
}
@ -144,9 +148,31 @@ import UIKit
@objc private func leftButtonTapped(button: UIButton) {
value -= 1
animateSlideLeft()
}
@objc private func rightButtonTapped(button: UIButton) {
value += 1
animateSlideRight()
}
private func animateSlideLeft() {
UIView.animateWithDuration(labelSlideDuration, animations: {
self.label.center.x -= self.labelSlideLength
}, completion : { _ in
UIView.animateWithDuration(self.labelSlideDuration, animations: {
self.label.center.x += self.labelSlideLength
})
})
}
private func animateSlideRight() {
UIView.animateWithDuration(labelSlideDuration, animations: {
self.label.center.x += self.labelSlideLength
}, completion : { _ in
UIView.animateWithDuration(self.labelSlideDuration, animations: {
self.label.center.x -= self.labelSlideLength
})
})
}
}