王筝的博客
ruby学习

开始写英文版本的博客了,嘻嘻

there are two more settings

(1)click the project-> Build Phases -> link Binary With Libraries -> click “+” -> search for “location” -> click the CoreLocation.framework, import the library to your project

(2)find info.plist,and add two keys and values

the first key is :NSLocationWhenInUseUsageDescription, you can put whatever you want in the value field to explain your reason to request user location,such as”Because I want to know where you are”. this can help you to request user location when the app is running.

the second key is:NSLocationAlwaysUsageDescription,you can puts reasons in the value field such as”Because I always want to know your locations”,this can help you in any time to get the user location ,even the app is not running.

https://cocoapods.org/

(1)sudo gem install cocoapods

(2)新建一个xcode应用

(3)从终端进入应用目录,pod init

(4) 修改生成的profile文件

platform :ios, ‘8.0’

use_frameworks!

 

target ‘MyApp’ do

  pod ‘AFNetworking’, ‘~> 2.6′

  pod ‘ORStackView’, ‘~> 3.0′

  pod ‘SwiftyJSON’, ‘~> 2.3’

end

 

(5)$ pod install

(6)open App.xcworkspace

(7)Now you can import your dependencies e.g.:

#import <Reachability/Reachability.h>

 

如果在swift项目中使用ios的控件,不要忘记写转换文件,Create Bridge Header,

之后需要在Build setting下的Swift Compiler-Code Generation里配置下bridge header路径。

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

To import Objective-C code into Swift from the same target

  1. In your Objective-C bridging header file, import every Objective-C header you want to expose to Swift. For example:

    1. #import "XYZCustomCell.h"
    2. #import "XYZCustomView.h"
    3. #import "XYZCustomViewController.h"
  2. In Build Settings, in Swift Compiler – Code Generation, make sure the Objective-C Bridging Header build setting under has a path to the bridging header file.

    The path should be relative to your project, similar to the way your Info.plist path is specified in Build Settings. In most cases, you should not need to modify this setting.

 

一个最简易的动画效果,

 

 

 

 

 

 

//  ViewController.swift
//  Animations
//  Created by WZ on 16/1/15.
//  Copyright © 2016年 iwangzheng.com. All rights reserved.

import UIKit

class ViewController: UIViewController {
    
    var count = 1
    var timer = NSTimer()
    var isAnimating = true
    
    @IBOutlet weak var Image: UIImageView!
    
    @IBAction func nextBtn(sender: AnyObject) {
        if isAnimating == true{
           timer.invalidate()
            isAnimating = false
        }else{
             timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: Selector("doAnimaition"), userInfo: nil, repeats: true)
            isAnimating = true
        }
        
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector: Selector("doAnimaition"), userInfo: nil, repeats: true)
    }

    func doAnimaition(){
        if count < 4{
            count++
        }else
        {
            count = 1
        }
        Image.image = UIImage(named: "\(count)")
    
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    /*
    override func viewDidLayoutSubviews() {
       // Image.center = CGPointMake(Image.center.x - 400, Image.center.y) //从左往右
        //Image.alpha = 0 //从无到有
        Image.frame = CGRectMake(100, 20, 0, 0)//改变大小
    }
    override func viewDidAppear(animated: Bool) {
        UIView.animateWithDuration(1,animations: { () -> Void in
            //self.Image.center = CGPointMake(self.Image.center.x + 400, self.Image.center.y)
           // self.Image.alpha = 1
            self.Image.frame = CGRectMake(100, 20, 100, 200)
        })
    }
    */


}

 

//: Playground - noun: a place where people can play

import UIKit

var str = "Hello"

var newString = str + "Lucy"

var newTypeString = NSString(string: newString)

newTypeString.substringFromIndex(5)

newTypeString.substringToIndex(5)

newTypeString.substringWithRange(NSRange(location: 3, length: 5))

if newTypeString.containsString("Lucy"){
  print("Hi")
}

newTypeString.componentsSeparatedByString("o")

newTypeString.uppercaseString

newTypeString.lowercaseString

 

import UIKit

class ViewController: UIViewController {
    
    var time = 0
    
    func result(){
        time++
        print(time)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        var timer = NSTimer()
        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: ("result"), userInfo: nil, repeats: true)
        
    }