受网页版 YouTube 播放按钮启发的 iOS 动画播放按钮。
将 PlaybackButton.swift
文件添加到项目中。
在您的文件中添加 import PlaybackButton
在您的 ViewController 中
@IBOutlet weak var playbackButton: PlaybackButton!
self.playbackButton.layer.cornerRadius = self.playbackButton.frame.size.height / 2
self.playbackButton.layer.borderWidth = 2.0
self.playbackButton.adjustMargin = 1
self.playbackButton2.duration = 0.3 // animation duration default 0.24
@IBAction func didTapPlaybackButton(sender: AnyObject) {
if self.playbackButton.buttonState == .Playing {
self.playbackButton.setButtonState(.Pausing, animated: true)
} else if self.playbackButton.buttonState == .Pausing {
self.playbackButton.setButtonState(.Playing, animated: true)
}
}
var playbackButton: PlaybackButton!
self.playbackButton = PlaybackButton(frame: CGRect(x: 0, y:20, width: 100, height: 100 ))
self.playbackButton.contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
self.playbackButton.adjustMargin = 0
self.playbackButton.addTarget(self, action: "didTapPlaybackButton:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(self.playbackButton)
func didTapPlaybackButton(sender: AnyObject) {
if self.playbackButton.buttonState == .Playing {
self.playbackButton.setButtonState(.Pausing, animated: true)
} else if self.playbackButton.buttonState == .Pausing {
self.playbackButton.setButtonState(.Playing, animated: true)
}
}
note1:
The position of PlaybackButton is based on top and left of ContentEdgeInsets.
Please regulate it at the position where wants to locate it.
note2:
The value of adjustMargin, please appoint 0-1.
The default is 0.
The left position of play becomes same as pause when adjustMargin is 1.
It is suitable to place PlaybackButton in the middle of view in the case of 0.
需要 Swift2.0 和 iOS 8.0 以及 ARC。
如果您想使用 iOS7.0,请直接导入代码。
欢迎分支、补丁和其他反馈。
PlaybackButton 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。