这个简单的线条动画让我有些挣扎。我想出了如何暂停它,但是我需要的是能够从调用函数resetAnimation()的那一刻起就将动画反向还原到起点。
let pathAnimation = CABasicAnimation(keyPath: "strokeEnd")
let pathLayer = CAShapeLayer()
func lineAnimation() {
let path = UIBezierPath()
let screenWidth = self.view.bounds.width
let screenHeight = self.view.bounds.height
path.moveToPoint(CGPointMake(screenWidth, screenHeight / 2))
path.addLineToPoint(CGPointMake(screenWidth - screenWidth, screenHeight / 2))
self.pathLayer.frame = self.view.bounds
self.pathLayer.path = path.CGPath
self.pathLayer.strokeColor = UIColor.whiteColor().CGColor
self.pathLayer.fillColor = nil
self.pathLayer.lineWidth = 3.0
self.pathLayer.lineCap = kCALineCapRound
self.pathLayer.speed = 1
self.view.layer.addSublayer(pathLayer)
self.pathAnimation.duration = 5.0
self.pathAnimation.fromValue = 0.0
self.pathAnimation.toValue = 1.0
pathLayer.addAnimation(pathAnimation, forKey: "animate")
}
func pauseAnimation() {
let pausedTime = pathLayer.convertTime(CACurrentMediaTime(), fromLayer: nil)
pathLayer.speed …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序上创建 Facebook 共享按钮,该按钮共享从 UIImageview 加载的图像。我不知道该怎么做.. 可以选择在 Facebook 共享窗口上添加文本,但无法添加图像。请帮忙。
import UIKit
import Social
class ViewController: UIViewController {
@IBOutlet weak var saveButtonVar: UIButton!
@IBOutlet weak var image: UIImageView!
@IBAction func facebookBtn(sender: AnyObject) {
var facebookBtn : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookBtn.setInitialText("I am sharing my motivation with you!")
facebookBtn.addImage(UIImage(named: "motImg")) //????
self.presentViewController(facebookBtn, animated: true, completion: nil)
}
@IBAction func twitterBtn(sender: AnyObject) {
}
@IBAction func saveButton(sender: AnyObject) {
UIImageWriteToSavedPhotosAlbum(image.image, nil, nil, nil)
let alertController = UIAlertController(title: "Image Saved!", message:
"", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: …Run Code Online (Sandbox Code Playgroud) 我是新手,对我遇到的这个问题感到沮丧.
我想要做的非常简单:在屏幕中央画一条直线并为其制作动画.听起来很简单吧?是啊..这就是我现在所拥有的.
import UIKit
class Drawings: UIView {
override func drawRect(rect: CGRect) {
let screensize: CGRect = UIScreen.mainScreen().bounds
let screenWidth = screensize.width
let screenHeight = screensize.height
//context
let context = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context, 7.0)
CGContextSetStrokeColorWithColor(context, UIColor.whiteColor().CGColor)
//path
CGContextMoveToPoint(context, screenWidth, screenHeight * 0.5)
CGContextAddLineToPoint(context, screenWidth * 0.5, screenHeight * 0.5)
CGContextSetLineCap(context, CGLineCap.Round)
//draw
CGContextStrokePath(context)
}
}
Run Code Online (Sandbox Code Playgroud)
我问的原因是我发现我无法为它设置动画,因为它在drawRect函数中.真的吗?需要你们的一些解释.谢谢!