How long has swift been around? I saw a variety of screaming parties, translation parties, black apple parties, and video teaching parties spring up and burst out ...... I would like to say that people with a little development foundation can simply look at the document. After all, the language is used.
It took me one afternoon to try swift to write the simplest UILabel animation and paste the Code:
import UIKitimport QuartzCoreclass FLabel :UIView { @lazy var mainLabel = UILabel() func setLabel(ftext:NSString?, ffont:CGFloat, falpha:CGFloat, flocation:CGPoint, fsize:CGSize){ mainLabel.font = UIFont(name: "Arial", size: ffont) mainLabel.text = ftext mainLabel.textColor = UIColor(white: 1, alpha: falpha) mainLabel.opaque = false mainLabel.layer.position = flocation mainLabel.layer.bounds = CGRectMake(0, 0, fsize.width, fsize.height) mainLabel.transform = CGAffineTransformMakeRotation(0.785) mainLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping mainLabel.adjustsFontSizeToFitWidth = true self.addSubview(mainLabel) } func animationStart(){ UILabel.beginAnimations("animationID", context: nil) UILabel.setAnimationDuration(6) UILabel.setAnimationCurve(UIViewAnimationCurve.Linear) let moveTransform2:CGAffineTransform = CGAffineTransformMakeRotation(0.785) let moveTransform:CGAffineTransform = CGAffineTransformTranslate(moveTransform2, 300, -300) mainLabel.layer.setAffineTransform(moveTransform) UILabel.commitAnimations() } }
Unfortunately, after vim and sublime are highlighted today, the Code display block of the blog garden is not highlighted yet. The document of Apple cocoa has helped me a lot, but it has also changed a lot. I hope those who really want to use swift to develop apps will still pay attention to cocoa.
Among them, UILabel. lineBreakMode is not the same as the previous method. As for adjustsFontSizeToFitWidth, I didn't try it out.
The animation in it was originally intended to use an explicit animation. It was found that the animationWithKeyPath was not used. After trying many methods, it could only be used as an implicit animation. Then the value of CGAffineTransformMakeRotation would not be solved, it is impossible to do animation without any mathematical foundation...
This code is not reflected. Today I tried init ()
“convenience init(parameters) { statements}”
This method of overloading constructors is indeed interesting and meaningful.
Now, the proporty in swift is much easier to use, and syntax is a bit like C #. I don't have the concept of public and private permissions in C #, which makes me feel strange. In short, after this messy exploration, this UILabel can finally be floated.
Welcome to visit qingjianfei blood article, reprinted please indicate the source of http://www.cnblogs.com/jacklandrin/p/3768777.html