Slow load time for custom UIView with UITextView property in Swift

后端 未结 4 1385
一生所求
一生所求 2020-12-16 11:01

I originally asked this question. I had assumed that the reason for the slow load time of my custom view was because of layering multiple views on top of each other or perha

4条回答
  •  时光取名叫无心
    2020-12-16 11:16

    downloaded your code from github, why don't you just write a subclass of UITextView instead of the UIView?

    //
    //  UIMongolTextView-A.swift
    //  Mongol App Componants
    //
    //  Created by Allen Zhang on 12/13/15.
    //  Copyright © 2015 MongolSuragch. All rights reserved.
    //
    
    import UIKit
    
    class UIMongolTextView_A: UITextView {
    
        override func awakeFromNib() {
            super.awakeFromNib()
            self.setup()
        }
    
        func setup() {
            // 1-10: ᠨᠢᠭᠡ ᠬᠤᠶᠠᠷ ᠭᠤᠷᠪᠠ ᠳᠦᠷᠪᠡ ᠲᠠᠪᠤ ᠵᠢᠷᠭᠤᠭ᠎ᠠ ᠳᠤᠯᠤᠭ᠎ᠠ ᠨᠠᠢ᠌ᠮᠠ ᠶᠢᠰᠦ ᠠᠷᠪᠠ
    
            self.transform = translateRotateFlip()
    
    
        }
    
        /*
        // Only override drawRect: if you perform custom drawing.
        // An empty implementation adversely affects performance during animation.
        override func drawRect(rect: CGRect) {
            // Drawing code
        }
        */
        func translateRotateFlip() -> CGAffineTransform {
    
            var transform = CGAffineTransformIdentity
    
            // translate to new center
            transform = CGAffineTransformTranslate(transform, (self.bounds.width / 2)-(self.bounds.height / 2), (self.bounds.height / 2)-(self.bounds.width / 2))
            // rotate counterclockwise around center
            transform = CGAffineTransformRotate(transform, CGFloat(-M_PI_2))
            // flip vertically
            transform = CGAffineTransformScale(transform, -1, 1)
    
            return transform
        }
    }
    

提交回复
热议问题