效果圖:壓縮很厲害
<br />
<br />
1诚亚、UI:ImageView、VisualEffectView滴某、Button磅摹、Label
UI比較簡單,不做介紹
1.1按鈕布局霎奢,
-
1.創(chuàng)建一個(gè)類户誓,繼承與UIButton
-
2.重寫layoutSubviews
override func layoutSubviews() {
super.layoutSubviews()
self.imageView?.frame = self.bounds
self.titleLabel?.removeFromSuperview()
self.titleLabel?.frame = self.bounds
self.titleLabel?.textAlignment = NSTextAlignment.Center
self.insertSubview(self.titleLabel!, aboveSubview: self.imageView!)
}
<br />
<br />
2、定位幕侠、閉包帝美、動(dòng)畫
<br />
2.1 定位、閉包
- 1 創(chuàng)建一個(gè)類橙依,繼承:ViewController
- 2 import CoreLocatioin
- 3 定義一個(gè)CLLocationManager對象
- 4 寫一個(gè)方法证舟,用于開啟定位
- 5 監(jiān)聽回調(diào)
- 6 解析并返回
import UIKit
import CoreLocation
/*
plist文件里面加上
NSLocationAlwaysUsageDescription string 你在這里寫的內(nèi)容會提示在彈窗中
NSLocationWhenInUseUsageDescription string 你在這里寫的內(nèi)容會提示在彈窗中
**/
//閉包定義
typealias feedBackBlock = (message : String) -> ()
class LocationViewController: UIViewController , CLLocationManagerDelegate{
var locationManager :CLLocationManager!
var block = feedBackBlock?()
var timer : NSTimer?
override func viewDidLoad() {
super.viewDidLoad()
}
func startLocation(feedBack :feedBackBlock){
block = feedBack
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
//模擬定位獲取成功
// timer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: #selector(self.send), userInfo: nil, repeats: true)
}
func send(){
timer?.invalidate()
timer = nil
block!(message: "來自遙遠(yuǎn)的國度,手機(jī)可獲得真實(shí)位置")
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print(error)
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error)->Void in
self.locationManager.stopUpdatingLocation()
if (error != nil) {
print("Reverse geocoder failed with error" + error!.localizedDescription)
return
}
if placemarks!.count > 0 {
let pm = placemarks![0]
self.displayLocationInfo(pm)
} else {
print("Problem with the data received from geocoder")
}
})
}
func displayLocationInfo(placemark: CLPlacemark?) {
if let containsPlacemark = placemark {
if block != nil {
self.block!(message: containsPlacemark.name!)
}
}
}
}
2.2 動(dòng)畫
- 1 把imageView、button窗骑、label拖線到ViewController中
- 2 在button的點(diǎn)擊事件調(diào)用開始定位的方法
startLocation { ( message) in
print(message)
self.address.text = message
let cat = CATransition();
cat.type = "cube"
cat.duration = 1
self.address.layer.addAnimation(cat, forKey: nil)
}
- 3 重寫touchesBegan
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
let cat = CATransition();
cat.type = "rippleEffect"
cat.duration = 1
view.layer.addAnimation(cat, forKey: nil)
changeBackgroundImage()
}
var item : Int = 1
func changeBackgroundImage(){
item += 1
if item > 6 {
item = 1
}
backgroundImage.image = UIImage(named: "c\(item).jpg")
}
<br />
<br />
簡單的介紹一下CATransition
type:動(dòng)畫類型:
kCATransitionFade 交叉淡化過渡
kCATransitionMoveIn 新視圖移到舊視圖上面
kCATransitionPush 新視圖把舊視圖推出去
kCATransitionReveal 將舊視圖移開,顯示下面的新視圖
pageCurl 向上翻一頁
pageUnCurl 向下翻一頁
rippleEffect 滴水效果
suckEffect 收縮效果女责,如一塊布被抽走
cube 立方體效果
oglFlip 上下翻轉(zhuǎn)效果
3 duration:動(dòng)畫時(shí)長
4 timingFunction:動(dòng)畫執(zhí)行(先快后慢,先慢后快……)
5 subType:方向(fromLeft, fromRight, fromTop ,fromBottom)
6 startProgress:開始點(diǎn) 0-1取值
7 endProgress:結(jié)束點(diǎn) 0-1取值
OK,到這里功能就完成了创译,如果項(xiàng)目有需要的時(shí)候抵知,就可以把自己創(chuàng)建的ViewController拿走,讓后頁面中繼承他,就可以使用獲取定位的方法了
<br /><br /><br />