Open 1c7 opened 9 years ago
只有2个功能,一个是点击按钮键盘会收起来,第二个是点击背景键盘也会收起来
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var email: UITextField!
@IBOutlet weak var password: UITextField!
// 点击按钮收起键盘
@IBAction func aaa(sender: UIButton) {
self.email.resignFirstResponder()
self.password.resignFirstResponder()
}
// 点击屏幕其他地方收起键盘
// 输入 touchB 然后用回车自动补全就可以了
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
}
import UIKit
class ViewController: UIViewController, UITableViewDataSource {
let people = [
("coffee", "james bruans"),
("water", "007"),
("orange juice", "kolu"),
("nice", "new york")
]
let videos = [
("android development", "32 video"),
("Java", "0 video"),
("Python programeing", "10 video"),
("Web", "110 videos")
]
// how many section
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
// how many row
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0{
return people.count
}else{
return videos.count
}
}
// content in each cell
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// indexPath 会从 0 开始,就是个循环
var ceil = UITableViewCell()
if indexPath.section == 0 {
var (personName, personLocation) = people[indexPath.row]
ceil.textLabel?.text = personName
}else{
var (videoTitle, videoDesc) = videos[indexPath.row]
ceil.textLabel?.text = videoTitle
}
return ceil
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0{
return "People"
}else{
return "Video"
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
import UIKit
class DrawExamples: UIView {
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
// 画东西都写在这里面 并不是只能画长方形
let context = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context, 3.0)
CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
// create a path
CGContextMoveToPoint(context, 30, 10)
CGContextAddLineToPoint(context, 250, 350)
//Actually draw the path
CGContextStrokePath(context)
}
}
import UIKit
class DrawExamples: UIView {
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// 画东西都写在这里面 并不是只能画长方形
let context = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context, 3.0)
CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
// create a path
// CGContextMoveToPoint(context, 30, 10)
// CGContextAddLineToPoint(context, 250, 350)
/*
CGContextMoveToPoint(context, 50, 50)
CGContextAddLineToPoint(context, 100, 100)
CGContextAddLineToPoint(context, 190, 230)
CGContextAddLineToPoint(context, 60, 130)
CGContextAddLineToPoint(context, 50, 50)
*/
// 长方形
let rect1 = CGRectMake(50, 50, 200, 400)
CGContextAddRect(context, rect1)
//Actually draw the path
CGContextStrokePath(context)
}
}
要重命名文件夹 选中之后按下回车就好
Command + Backspace 就是win键 加 删除前面文字的那个键
import UIKit
class DrawExamples: UIView {
override func drawRect(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
let a = UIImage(named: "a.jpg")
let b = UIImage(named: "b.jpg")
let location = CGPointMake(25, 25)
a?.drawAtPoint(location)
}
}
import UIKit
class DrawExamples: UIView {
override func drawRect(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
let a = UIImage(named: "a.jpg")
let b = UIImage(named: "b.jpg")
/// let location = CGPointMake(25, 25)
///a?.drawAtPoint(location)
let entireScreen = UIScreen.mainScreen().bounds
a?.drawInRect(entireScreen)
print(entireScreen)
}
}
![Uploading 屏幕快照 2015-10-22 下午7.40.19.png…]()
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var buckButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
UIView.animateWithDuration(3.0, animations: {
self.buckButton.alpha = 0
})
}
}
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var buckButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
UIView.animateWithDuration(3.0, animations: {
let grow = CGAffineTransformMakeScale(4,4)
// 变大四倍
let angle = CGFloat(40)
let rotate = CGAffineTransformMakeRotation(angle)
// 旋转
self.buckButton.transform = CGAffineTransformConcat(grow, rotate)
// 两个动画一起执行
})
}
}
import UIKit
class ViewController: UIViewController {
// Create two shape
var greenSqure : UIView?
var redSqure : UIView?
override func viewDidLoad() {
super.viewDidLoad()
// 弄个绿色方块
var dimen = CGRectMake(20, 20, 60, 60)
greenSqure = UIView(frame: dimen)
greenSqure?.backgroundColor = UIColor.greenColor()
// 弄个红色方块
dimen = CGRectMake(120, 120, 60, 60)
redSqure = UIView(frame: dimen)
redSqure?.backgroundColor = UIColor.redColor()
// 加到屏幕上
self.view.addSubview(greenSqure!)
self.view.addSubview(redSqure!)
}
}
会掉到屏幕外面去,因为没有底部
import UIKit
class ViewController: UIViewController {
// Create two shape
var greenSqure : UIView?
var redSqure : UIView?
var animator : UIDynamicAnimator?
override func viewDidLoad() {
super.viewDidLoad()
// 弄个绿色方块
var dimen = CGRectMake(20, 20, 60, 60)
greenSqure = UIView(frame: dimen)
greenSqure?.backgroundColor = UIColor.greenColor()
// 弄个红色方块
dimen = CGRectMake(120, 120, 60, 60)
redSqure = UIView(frame: dimen)
redSqure?.backgroundColor = UIColor.redColor()
// 加到屏幕上
self.view.addSubview(greenSqure!)
self.view.addSubview(redSqure!)
// Initialize the animator
animator = UIDynamicAnimator(referenceView: self.view)
// add gravity
let gravity = UIGravityBehavior(items: [greenSqure!, redSqure!])
let direction = CGVectorMake(0.0, 1.0)
gravity.gravityDirection = direction
animator?.addBehavior(gravity)
}
}
import UIKit
class ViewController: UIViewController {
// Create two shape
var greenSqure : UIView?
var redSqure : UIView?
var animator : UIDynamicAnimator?
override func viewDidLoad() {
super.viewDidLoad()
// 弄个绿色方块
var dimen = CGRectMake(20, 20, 60, 60)
greenSqure = UIView(frame: dimen)
greenSqure?.backgroundColor = UIColor.greenColor()
// 弄个红色方块
dimen = CGRectMake(120, 120, 60, 60)
redSqure = UIView(frame: dimen)
redSqure?.backgroundColor = UIColor.redColor()
// 加到屏幕上
self.view.addSubview(greenSqure!)
self.view.addSubview(redSqure!)
// Initialize the animator
animator = UIDynamicAnimator(referenceView: self.view)
// add gravity
let gravity = UIGravityBehavior(items: [greenSqure!, redSqure!])
let direction = CGVectorMake(0.0, 1.0)
gravity.gravityDirection = direction
// 加上碰撞 效果
let boundries = UICollisionBehavior(items: [greenSqure!, redSqure!])
boundries.translatesReferenceBoundsIntoBoundary = true
animator?.addBehavior(boundries)
animator?.addBehavior(gravity)
}
}
![Uploading 屏幕快照 2015-10-23 上午10.41.42.png…]()
import UIKit
class ViewController: UIViewController {
// Create two shape
var greenSqure : UIView?
var redSqure : UIView?
var animator : UIDynamicAnimator?
override func viewDidLoad() {
super.viewDidLoad()
// 弄个绿色方块
var dimen = CGRectMake(20, 20, 60, 60)
greenSqure = UIView(frame: dimen)
greenSqure?.backgroundColor = UIColor.greenColor()
// 弄个红色方块
dimen = CGRectMake(120, 120, 60, 60)
redSqure = UIView(frame: dimen)
redSqure?.backgroundColor = UIColor.redColor()
// 加到屏幕上
self.view.addSubview(greenSqure!)
self.view.addSubview(redSqure!)
// Initialize the animator
animator = UIDynamicAnimator(referenceView: self.view)
// add gravity
let gravity = UIGravityBehavior(items: [greenSqure!, redSqure!])
let direction = CGVectorMake(0.0, 1.0)
gravity.gravityDirection = direction
// 加上碰撞 效果
let boundries = UICollisionBehavior(items: [greenSqure!, redSqure!])
boundries.translatesReferenceBoundsIntoBoundary = true
// Elasticity
let bound = UIDynamicItemBehavior(items: [greenSqure!, redSqure!])
bound.elasticity = 0.5
animator?.addBehavior(boundries)
animator?.addBehavior(gravity)
animator?.addBehavior(bound)
}
}
按钮
原本 左边的设计不是这样的,左边是一个 label,2个button,后面改了又撤销不回来。所以无所谓了。反正这帖子相当于某种学习日记而已。