iOS-技术细节整理

遇到未使用类,可以看看xcode->help->developer documentation

下面做一下简单的技术细节整理

Auto Layout
使用Auto Layout来灵活改变UI elements,使得各个元素可以使用不同尺寸、翻转状态的屏幕。红线表示还有未声明的约束。
术语:
leading trailing top bottom 左右上下
margin边界

建立storyboard与viewcontroller
联系建立后,viewcontroller中的代码名称不可修改,否则无法索引

添加viewcontroller控件
建立storyboard与viewcontroller之间的联系,与viewcontroller自定义类绑定;
可以在attribute inspector中设置 is initial view controller,即为app的entry point

*Button
直接添加action响应函数

*slider
直接添加action响应函数(event: value changed)

*显示提示信息
舍弃UIAlertView,需要使用UIAlertController

UIAlertController
可以设置title、message,可以添加UIAlertAction
使用viewcontroller的present显示(alert是模态视图)
func present(UIViewController, animated: Bool, completion: (() -> Void)? = nil)
Presents a view controller modally.

UIAlertAction
An action that can be taken when the user taps a button in an alert.
原本的提示框转到了界面下方的模态视图
模态视图理解为一个浮动在原先视图上的一个临时性的视图或者界面

note:模态视图
覆盖于原有view之上的临时图层

*访问相机和照片
info中添加key Privacy - Camera Usage Description

 

建立ui和viewcontroller的联系(outlet、action)

Outlets let you refer to your interface elements in code, but you still need a way to respond whenever the user interacts with the elements. That’s where actions come in.

 

event-driven programming

iOS apps are based on event-driven programming. That is, the flow of the app is determined by events: system events and user actions. 

target-action pattern

target-action pattern in iOS app design. Target-action is a design pattern where one object sends a message to another object when a specific event occurs.

for example:

The event is the user tapping the Set Default Text button.

The action is setDefaultLabelText(_).

The target is ViewController (where the action method is defined).

The sender is the Set Default Label Text button.

The system sends the message by calling the action method on the target and passing in the sender object. The sender is usually a control—such as a button, slider, or switch—that can trigger an event in response to user interaction such as a tap, drag, or value change.

delegate

Any object can serve as a delegate for another object as long as it conforms to the appropriate protocol.

textfield的delegate可以实现以下响应

    func textFieldDidEndEditing(_ textField: UITextField) {

    }

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {

    }

first responder

When the user taps a text field, it automatically becomes the first responder. In an app, the first responder is an object that is first on the line for receiving many kinds of app events, including key events, motion events, and action messages, among others. In other words, many of the events generated by the user are initially routed to the first responder.

When a user wants to finish editing the text field, the text field needs to resign its first-responder status. Because the text field will no longer be the active object in the app, events need to get routed to a more appropriate object.

 

tips

使用注释//MARK:、function menu快速索引

//MARK: Properties
//MARK: Actions

Functions menu

In Xcode, a jump menu that lets you navigate directly to a specific declaration or section in a source code file.

 

posted @ 2017-08-25 17:03  ceo1207  阅读(176)  评论(0编辑  收藏  举报