"Swift" iOS Development Pit Adventures (ii)

Source: Internet
Author: User

Objective

This series is mainly in some development encountered in the pit record sharing, help beginners to cross these pits, save enough 7 to send an article.

Statement
Welcome reprint, but please keep the original source of the article:)
Blog Park: http://www.cnblogs.com
Farmer Uncle: Http://over140.cnblogs.com

Body

1. Does the animation update the constraint without animation effect?

Missing layoutifneeded, Case:

        Uiview.animatewithduration (0.15             in             self.view.layoutIfNeeded ()   //  This line can not be less        })

2. Handling click and double-click conflicts

Singletaprecognizer.requiregesturerecognizertofail (Doubletaprecognizer)

However, with one problem, clicking on the response slows down, so it's a good idea to change the design.

3. Get UILabel number of rows (not subject to Lines restrictions)

extension UILabel {    , Int {        if let text = Self.text {            = NSString ( string : Text). Boundingrectwithsize (Cgsizemake (Bounds.width, Cgfloat.max), Options: Nsstringdrawingoptions.useslinefragmentorigin, attributes: [NSFontAttributeName:self.font], Context:nil)             return Int (ceil (size.height/ self.font.lineHeight))        }        return 0     }}

4. Custom sharing (share to Facebook, Twitter, Weibo)

Originally did not intend to write, mainly search time did not quickly search the relevant results

  Func sharesocialaction (servicetype:string) {Let VC  = Slcomposeviewcontroller (forservicetype:servicetype) vc.setinitialtext (  "
     Welcome to live    "  cover    Span style= "color: #0000ff;" >string :  https://shou.tv/over140    true  , Completion:nil)}  

The incoming slservicetypetwitter can share to Twitter, look for definitions to see the share to the other, here is a full: Oversharekit

    Note : Let VC = Slcomposeviewcontroller (forservicetype:servicetype) may return nil and need to be judged (the IPhone on the Internet may be blocked). My approach here is to take the Twitter and Facebook SDK to start sharing.

5. Iqkeyboardmanager Prohibit a Uitextfield toolbar

Disable toolbars for Viewcontroller levels: Iqkeyboardmanager.sharedmanager (). Disabletoolbarinviewcontrollerclass, if this UITextField This method of directly add to window is no use, you can set Inputaccessoryview = UIView () directly.

6, afnetworking 3.0 output Log

            Let Networklogger = Afnetworkactivitylogger.sharedlogger ()            networklogger.startlogging ()            =  Afnetworkactivityconsolelogger ()            = afhttprequestloggerlevel.afloggerleveldebug            Networklogger.addlogger (console)

7, Avcapturedevice.requestaccessformediatype authorization failure bomb uialertview need to put on the Dispatch_async (Dispatch_get_main_queue ()) Main Line

 Avcapturedevice.requestaccessformediatype (Avmediatypevideo, Completionhandler: {[weak self] (granted: Bool) in   granted { //  authorization succeeded } else   {
    //  authorization failed, bounce one uialertview   Dispatch_async (Dispatch_get_main_queue ()) { // uialertview ....   

If you do not add Dispatch_async (Dispatch_get_main_queue ()) This code, on some devices prompted Uialertview this line crashes.

Series

"Swift" iOS Development Pit Adventures (i)

"Swift" iOS Development Pit Adventures (ii)

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.