iOS 8自定义表情符号键盘内存问题 - Swift -

时间:2015-07-07 22:22:47

标签: swift ios8 instruments emoji custom-keyboard

我在键盘上添加了表情符号视图。我可以在模拟器上使用它,但是当我在我的iPhone 6上运行时,它崩溃了,因为内存无法处理所有表情符号(我认为)。仪器对我没什么帮助。这是我的代码

    // init emojis
    let peopleEmojiPath : String = NSBundle.mainBundle().pathForResource("People", ofType: "plist")!
    let peopleEmoji :NSArray = NSArray(contentsOfFile: peopleEmojiPath)!

    let natureEmojiPath : String = NSBundle.mainBundle().pathForResource("Nature", ofType: "plist")!
    let natureEmoji :NSArray = NSArray(contentsOfFile: natureEmojiPath)!

    let foodEmojiPath : String = NSBundle.mainBundle().pathForResource("Food&Drink", ofType: "plist")!
    let foodEmoji :NSArray = NSArray(contentsOfFile: foodEmojiPath)!

    let celebrationEmojiPath : String = NSBundle.mainBundle().pathForResource("Celebration", ofType: "plist")!
    let celebrationEmoji :NSArray = NSArray(contentsOfFile: celebrationEmojiPath)!

    let activityEmojiPath : String = NSBundle.mainBundle().pathForResource("Activity", ofType: "plist")!
    let activityEmoji :NSArray = NSArray(contentsOfFile: activityEmojiPath)!

    let travelEmojiPath : String = NSBundle.mainBundle().pathForResource("Travel&Places", ofType: "plist")!
    let travelEmoji :NSArray = NSArray(contentsOfFile: travelEmojiPath)!

    let objectsEmojiPath : String = NSBundle.mainBundle().pathForResource("Objects&Symbols", ofType: "plist")!
    let objectsEmoji :NSArray = NSArray(contentsOfFile: objectsEmojiPath)!
    // init emojis

    let BigEmojiArray : Array<NSArray> = [peopleEmoji,natureEmoji,foodEmoji,celebrationEmoji,activityEmoji,travelEmoji,objectsEmoji]
    var emojiButton : UIButton!

    var yPos : CGFloat = 1
    var xPos : CGFloat = 0

    var emojiScrollView : UIScrollView = UIScrollView(frame: CGRectMake(0, 0, self.frame.size.width, self.frame.size.height))
    emojiScrollView.showsHorizontalScrollIndicator = false


    for emojiArray in BigEmojiArray{
        for emojiString in emojiArray{
            emojiButton = UIButton.buttonWithType(.Custom) as! UIButton
            emojiButton.frame = CGRectMake(xPos, yPos, self.frame.size.height / 5, 40)
            emojiButton.setTitle(emojiString as? String, forState: .Normal)
            emojiButton.addTarget(self, action: "iAmEmojiButtonPressed:", forControlEvents: .TouchUpInside)
            emojiButton.titleLabel?.font = UIFont(name: "Apple Color Emoji", size: 31)

            if yPos  >= self.frame.size.height - self.frame.size.height / 5 - 1{
                xPos += 44
                yPos = 1
            }

            else{
                yPos += 43
            }

            emojiScrollView.addSubview(emojiButton)


        }


    }

    emojiScrollView.contentSize = CGSizeMake(xPos + 50, self.frame.size.height - self.frame.size.height / 5 - 1)
    self.addSubview(emojiScrollView)

}

这是仪器中的分配图像。你可以看到这里的大跳跃。当我按下将表情符号视图带到超级视图的按钮

时发生的一切

you can see the big jump here . all that happens when i press the button that brings the Emoji View to the super view

我需要知道问题出在哪里并解决它

0 个答案:

没有答案