Touches
Touch Event Handling: Some ways to add touch in Viewcontroller
Get Touch Point println (Touches.anyobject ()?. Locationinview (Self.view))
Multi-touch to open multi-touch in the Viewdidload,
Self.view.multipleTouchEnabled = True
To scale a picture:
Zooming and zooming is the distance between screens through multi-touch time. When the distance between two points is large, it is magnified, otherwise it is reduced
ifTouches.count = =2{var cunrentdistance:cgfloat=0var p1= touches.allobjects[0].locationinview (Self.view) var p2= touches.allobjects[1].locationinview (Self.view) var xx= p1.x-P2.xvar yy= p1.y-p2.ycunrentdistance= sqrt (xx*xx+yy*yy)ifCunrentdistance-lastdistance >5{ni.transform= Cgaffinetransformscale (Ni.transform,1.1,1.1) Lastdistance=Cunrentdistanceprintln ("Zoom in")//Zoom in}Else ifCunrentdistance-lastdistance <-5{ni.transform= Cgaffinetransformscale (Ni.transform,0.9,0.9) Lastdistance=Cunrentdistanceprintln ("Zoom Out")}}
1 Open Web page, if not open page on view, will automatically jump to safari to open
Uiapplication.sharedapplication (). OpenURL (Nsurl (string: "http://baidu.com")!)
Common open actions-send email, call, send text messages and open Web pages consistent only the agreement is different
Message is string: "Mailto://xxxxx"
Call string: "Tel://xxxxx"
Texting string: "Sms://xxxx"
Custom Open Protocol (that is, open another app inside one app)
1 Add a URL to the root node in Info.plist in the program being accessed types
2 This URL identity is replaced by the URL schemes and the protocol name is added
3 adding in the Appdelegate method
Func application (application:uiapplication, Handleopenurl url:nsurl), Bool
and provide a view in this method
4 Open the Custom Nsurl protocol in another program's method-----This Nsurl protocol requires a URL-compliant standard
Take pictures, get pictures of pictures in the Picture collection method
1 First define a Uiimagepickercontroller object and select the SourceType type of this object as Uiimagepickercontrollersourcetype
2 Set the delegate for this object to self, which needs to inherit Uiimagepickercontrollerdelegate, Uinavigationcontrollerdelegate protocol, and implement the Imagepickercontroller method
The parameter info in this method is the information of the photo, var image = Info[uiimagepickercontrolleroriginalimage] as UIImage
Assign a value to a ImageView object by this command
and exit the current gallery by Picker's Dismissviewcontrolleranimated method
iOS app sandbox, write file
iOS uses sandbox mode to keep data safe, read-write is built on the sandbox
1 First access to the program's directory, the program home directory only four folders,
The following command is accessed to the Documen folder, and the second parameter is access to all files
var sp = Nssearchpathfordirectoriesindomains (Nssearchpathdirectory.documentdirectory, Nssearchpathdomainmask.alldomainsmask, True)
2 Write the file to the appropriate path
2.1 File data for
var data = Nsmutabledata ()
Data.appenddata ("Ni hao swift\n". Datausingencoding (nsutf8stringencoding, allowlossyconversion:true)!)
2.2 Put it under the path
Data.writetofile (url?. path!)! , atomically:true)
Read file:
Read to program Measure1
var data = NSData (contentsoffile: (url?. PATH)!)
var str = nsstring (data:data!, encoding:nsutf8stringencoding)
Read to program Measure2 if you know the file is a string
var str = nsstring (contentsofurl:url!, encoding:nsutf8stringencoding, Error:nil)
User preference data--only common types and small data--the program exits and the program data is not lost
1 Storing user preference data
var ud = nsuserdefaults.standarduserdefaults ()
Ud.setobject (Savedtext.text, Forkey: "Data")
println ("Saved")
2 Reading user preference data
Last Saved by Objectforkey (this method can be implemented in viewdidload)
iOS Learning essay Five