Swift animation Test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.