iOS development-Project Combat Swift &swift 2.0 Project Development Summary II (Common development)

Source: Internet
Author: User

Swift 2.0 Project Development Summary II (common development)A: Photo album in the selection of photos to the app location with the increase in camera pixels, the actual user selected pictures are very large, and some up to 5.6M, if directly using the user selected pictures, very consumption of memory, and also can not use such a high-pixel picture, when the user selected a good picture, In the Uiimagepickercontroller corresponding proxy method, the picture is redrawn to the desired size, set to IconView
1 ///MARK: Action and proxy methods for cameras and albums2 extension meviewcontroller:uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate {3 4   ///turn on the camera function5   Privatefunc Opencamera () {6       ifuiimagepickercontroller.issourcetypeavailable (. Camera) {7Pickvc.sourcetype = . Camera8Self.presentviewcontroller (PICKVC, animated:true, Completion:nil)9}Else {TenSvprogresshud.showerrorwithstatus ("Simulator does not have a webcam, please link the real machine debugging", MaskType:SVProgressHUDMaskType.Black) One       } A   } -  -   ///Open Album the   Privatefunc openuserphotolibrary () { -Pickvc.sourcetype = . Photolibrary -Pickvc.allowsediting =true -Presentviewcontroller (PICKVC, animated:true, Completion:nil) +   } -  + func Imagepickercontroller (picker:uiimagepickercontroller, didfinishpickingmediawithinfo info: [String: Anyobject]) { A       //quality compression for user-selected images, upload server, local persistent storage at       ifLet Typestr = Info[uiimagepickercontrollermediatype] as?String { -           ifTypestr = ="Public.image" { -               ifLet image = Info[uiimagepickercontrollereditedimage] as?UIImage { -var data:nsdata? -Let Smallimage = uiimage.imagecliptonewimage (image, newsize:iconview!. Iconbutton.size) -                   ifUiimagepngrepresentation (smallimage) = =Nil { indata = UIImageJPEGRepresentation (Smallimage,0.8) -}Else { todata =uiimagepngrepresentation (smallimage) +                   } -  the                   ifData! =Nil { *                        Do { $                           //TODO: Send Avatar's data to the serverPanax Notoginseng                           //a copy of data is also kept locally -                           TryNsfilemanager.defaultmanager (). Createdirectoryatpath (Theme.cachespath, withintermediatedirectories:true, Attributes:nil) the}Catch _ { +                       } A Nsfilemanager.defaultmanager (). Createfileatpath (Sd_usericondata_path, Contents:data, attributes : nil) the  +iconview!. Iconbutton.setimage (UIImage (Data:nsdata (contentsoffile:sd_usericondata_path)!)!. Imageclipovalimage (), forstate:. Normal) -  $}Else { $Svprogresshud.showerrorwithstatus ("Photo Save failed", MaskType:SVProgressHUDMaskType.Black) -                   } -               } the           } -}Else {WuyiSvprogresshud.showerrorwithstatus ("picture cannot be retrieved", MaskType:SVProgressHUDMaskType.Black) the       } -  WuPicker.dismissviewcontrolleranimated (true, Completion:nil) -   } About  $ func Imagepickercontrollerdidcancel (picker:uiimagepickercontroller) { -Pickvc.dismissviewcontrolleranimated (true, Completion:nil) -   } - } A  

Second: The realization of shaking and shaking function
1 OverrideFunc Motionbegan (Motion:uieventsubtype, witheventEvent: Uievent?) {2tableview!. Hidden =true3Let Animateduration:nstimeinterval =0.34Let offsety:cgfloat = -5 6Uiview.animatewithduration (animateduration, animations: {()-Voidinch7Self.yaoImageView1.transform = Cgaffinetransformmaketranslation (0, -OffsetY)8Self.yaoImageView2.transform = Cgaffinetransformmaketranslation (0, OffsetY)9 Ten}) {(finish)-Voidinch OneLet Poptime = Dispatch_time (Dispatch_time_now,int64 (0.5*Double (nsec_per_sec))) ADispatch_after (Poptime, Dispatch_get_main_queue (), {(), Voidinch -  -Uiview.animatewithduration (animateduration, animations: {()-Voidinch theSelf.yaoImageView1.transform =cgaffinetransformidentity -Self.yaoImageView2.transform =cgaffinetransformidentity -}, Completion: {(finish), Voidinch -  + Self.loadshakedata () -                           //Sound +Audioservicesplayalertsound (self.soundid!) A                   }) at               }) -}

iOS development-Project Combat Swift &swift 2.0 Project Development Summary II (Common development)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.