我有一个无限的“翻转”到标签(这是一个水印),我需要“关闭”到一个特定的标签(或水印)时,股票期权正在显示。所有这些都是通过计时器实现的——在翻页之前,将特定标签查看几秒钟。当你这样做时,只需关闭计时器。
public class FlipView:UIView {
private var labelWatermark:FlipLabel!
private var labelTap:FlipLabel!
let transitionOptions: UIViewAnimationOptions = [.transitionFlipFromRight, .showHideTransitionViews]
var isLabel1 = true
var timer:Timer!
convenience public init(appName:String) {
self.init(frame: CGRect.zero)
labelTap = FlipLabel("Tap to remove", "Watermark")
self.addSubview(labelTap)
labelWatermark = FlipLabel("created with", appName)
self.addSubview(labelWatermark)
timer = Timer.scheduledTimer(
timeInterval: 3.0, target: self, selector: #selector(flipViews),
userInfo: nil, repeats: true)
timer.fire()
}
internal func startFlip() {
timer = Timer.scheduledTimer(
timeInterval: 3.0, target: self, selector: #selector(flipViews),
userInfo: nil, repeats: true)
timer.fire()
}
internal func stopFlip() {
timer.invalidate()
UIView.transition(from: labelTap, to: labelWatermark, duration: 1, options: transitionOptions, completion: nil)
isLabel1 = true
}
@objc func flipViews() {
if (isLabel1) {
UIView.transition(from: labelWatermark, to: labelTap, duration: 1, options: transitionOptions, completion: nil)
isLabel1 = false
} else {
UIView.transition(from: labelTap, to: labelWatermark, duration: 1, options: transitionOptions, completion: nil)
isLabel1 = true
}
}
}