• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cheng-kang/iosDev: Try to learn and practice developing iOS app with Swift.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

cheng-kang/iosDev

开源软件地址:

https://github.com/cheng-kang/iosDev

开源编程语言:

Swift 99.6%

开源软件介绍:

iosDev

Records of my Swift iOS development journey.

A GitBook version of the notes below has been created, check here: Swift Newbie.

If you want to contribute, please contact me ([email protected]).

部分项目截图、涉及内容的介绍:《Intro to Projects》。例如:

Anchors

  1. Practice Project Status
  2. Articles
  3. Learning Materials
  4. Notes

Practice Project Status

  • FenghuangXinwen UI: working
  • Instagram UI: working
  • Weibo UI: working
  • PokeDex: working
  • MySongs: working
  • Calculator: working
  • A Simple Web Browser: working
  • My Rock Pet: working
  • MyHood: working
  • To-do List: working
  • Trapper (Tapper): working

Articles

Articles written by myself during my journey to iOS development. The articles are listed in reverse chronological order.

Learning Materials

ios tutorial

videos better watch again:

websites to check

Transform

print(img.frame.height)
var tf = CATransform3DIdentity
tf.m34 = 1/(-500)
tf = CATransform3DRotate(tf, -45.0 * CGFloat(M_PI) / 180.0, 1.0, 0.0, 0.0)
self.img.layer.transform = tf
print(img.frame.height)

音频截取

informative links

Nice Frameworks

Notes

If the layout isn't what you expect, check if you've added the constraints!!!

Use 'Equal Widths' to set the width of any StackView inside ScrollView, otherwise the width will go wrong.

1.change present view

1 set storyboard_id

2 for example: Swift let tv = self.storyboard?.instantiateViewControllerWithIdentifier("TapViewController") as! TapViewController self.presentViewController(tv, animated: true, completion: nil)

2.differences between the content modes

differences between the content modes

###3.how to load and play a audio

How to play sounds using AVAudioPlayer

drag the audio file to the app directory and just press enter

import UIKit
import AVFoundation

class ViewController: UIViewController{
    
    var btnSound: AVAudioPlayer!
    override func viewDidLoad() {
        super.viewDidLoad()
        let path = NSBundle.mainBundle().pathForResource("btn", ofType: "wav")
        let soundUrl = NSURL(fileURLWithPath: path!)
        
        do {
            try btnSound = AVAudioPlayer(contentsOfURL: soundUrl)
            btnSound.prepareToPlay()
        } catch {
            
        }
    }
    ...

4.animationImages

    @IBOutlet weak var monsterImg: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        var imgArray = [UIImage]()
        //init your image array, for example
        for var x = 1; x <= 4; x++ {
            let img = UIImage(named: "idle\(x).png")
            imgArray.append(img!)
        }
        
        monsterImg.animationImages = imgArray
        monsterImg.animationDuration = 0.8
        monsterImg.animationRepeatCount = 0
        monsterImg.startAnimating()
        
        //animationImages
        //An array of UIImage objects to use for an animation.
        
        //animationDuration
        //The amount of time it takes to go through one cycle of the images.
        //The time duration is measured in seconds. The default value of this property is equal to the number of images multiplied by 1/30th of a second. Thus, if you had 30 images, the value would be 1 second.
        
        //animationRepeatCount
        //Specifies the number of times to repeat the animation.
        //The default value is 0, which specifies to repeat the animation indefinitely.
    }

5.a dragable image class

import Foundation
import UIKit

class DragImg: UIImageView {
    
    var originalPosition: CGPoint!
    
    //why override this?
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    //what's this?
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        originalPosition = self.center
    }
    
    override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
        if let touch = touches.first {
            let position = touch.locationInView(self.superview)
            self.center = CGPointMake(position.x, position.y)
        }
    }
    
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        self.center = originalPosition
    }
}

6.NSTimer

var timer: NSTimer!
timer = NSTimer.scheduledTimerWithTimeInterval(TIME_INCREMENT, target:self, selector: "FUNCTION", userInfo: nil, repeats: BOOL)

7.NSNotificationCenter

//somewhere
NSNotificationCenter.defaultCenter().postNotification(NSNotification(name: "NOTIFICATION_NAME", object: nil))

//somewhere else
NSNotificationCenter.defaultCenter().addObserver(self, selector: "FUNCTION", name: "NOTIFICATION_NAME", object: nil)

8.must add these init when create a subclass of UIImageView

    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

An article about 'init': Swift init patterns

9.Segue

pass message to the next segue

//somewhere
  performSegueWithIdentifier("IDENTIFIER", sender: A_SENDER)
  
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyOBject?) {
  if segue.identifier == "IDENTIFIER" {
    if let whatVC = segue.destinationViewController as ? SomeViewController {
      if let theString = sender as? String {
        whatVC.someStr = theString
      }
    }
  }
}

10.Extensions

extension Double {
  var currency: String {
    return "$\(self)"
  }
}

11.To load page with http protocol

edit the info.plist

NSAppTransportSecurity Dictionary
NSAllowsArbitraryLoads Boolean YES

11.hide keyboard

Add the following to your viewDidLoad():

let tap = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)

and then add the following method declaration:

func dismissKeyboard()
{
    view.endEditing(true)
}

12.UITableViewCell automatic resizing

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

参考:Automatically resizing UITableViewCells with Dynamic Type and NSAttributedString

13.change view size

view.frame.CGRectMake(0 , 0, self.view.frame.width, self.view.frame.height * 0.7) 

14.set UICollectionViewCell spacing & line spacing

let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
layout.minimumInteritemSpacing = 1
layout.minimumLineSpacing = 1

collectionView.collectionViewLayout = layout

15.UITableViewCell Animation

override willDisplayCell

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell,
    forRowAtIndexPath indexPath: NSIndexPath) {
    //Animation Code
}

16.self.view.endEditing(true)

17.draw image with render color

drawImage(UIImage(named: "image")!, size: CGSizeMake(30, 30), renderColor: UIColor(red: 149.0/255, green: 149.0/255, blue: 149.0/255, alpha: 1))

18.replace sub-string

let text = (stringName as NSString).stringByReplacingOccurrencesOfString("whatever", withString: "")

19.The file “” couldn’t be opened because you don’t have permission t

clean and re-build

20.check if text is Int

if Int(strToCheck) == nil {
  print("Not Int")
} else {
  print("Is Int")
}

21.localizedStringWithFormat

String.localizedStringWithFormat(NSLocalizedString("Blahblahblah %d.", comment: "Some Comment"), intVar)

22.an alertView example, pop up at the screen center

import UIKit

class ExampleAlertView: UIView {
    
    
    @IBOutlet weak var wechatPayButton: UIButton!
    @IBOutlet weak var alipayButton: UIButton!
    
    @IBOutlet weak var amountTextField: UITextField!
    
    @IBOutlet weak var infoLabel: UILabel!
    
    private var shadowBtn: UIButton!
    
    let ApplicationDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
    private var showView: UIView {
        return ApplicationDelegate.window!
    }
    
    private var confirmClosure: (() -> ())?
    private var cancelClosure: (() -> ())?
    
    
    @objc private func shadowBtnClick() {
        
        UIView.animateWithDuration(0.15, animations: {
            self.shadowBtn.alpha = 0
            self.alpha = 0
        }) { (success) in
            self.shadowBtn.removeFromSuperview()
            self.removeFromSuperview()
        }
    }

    class  

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap