swift動畫小試牛刀

來源:互聯網
上載者:User

swift剛出沒多長時間,看到各種驚呼黨,翻譯黨,黑蘋果黨,視頻教學黨如雨後春筍版噴薄而出......我想說有點開發基礎的人,其實看看文檔也就行了,畢竟語言是拿來用的。

今天花了一下午的時間,沒有太看swift的syntax,而是試了試用swift寫個最最簡單的UILabel動畫,貼下代碼:

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()    }    }

 可惜,vim和sublime今天出了高亮之後,部落格園的代碼顯示塊還沒有高亮。蘋果cocoa的文檔給了我很大的協助,其中也發生了很大的變化,希望那些真正想用swift開發app的人,還是把注意力關注到cocoa上來。

其中UILabel.lineBreakMode和以前的方法不太一樣了,至於adjustsFontSizeToFitWidth我沒有試出作用來。

裡面動畫本來想用顯式動畫的,發現animationWithKeyPath不讓用了,試了很多方法都不行,只能用隱式動畫,然後就是CGAffineTransformMakeRotation那個值我真的不會解,做動畫沒點數學基礎是不行的。。。

這個代碼裡沒有體現,今天還試了一下init()

“convenience init(parameters) {    statements}”

這種重載建構函式的方法確實很有趣,也很有意義

話說現在swift中的proporty真的好用多了,完全的syntax有點像C#。然後沒有C#裡public和private的許可權概念讓我覺得怪怪的,總之,經過這亂七八糟的探索之後,這個UILabel終於可以飄了

 歡迎訪問傾劍飛血文章,轉載請註明出處 http://www.cnblogs.com/jacklandrin/p/3768777.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.