tvos: UITextView focus appearance like movies App

一个人想着一个人 提交于 2019-12-01 03:45:37

问题


I am building a tvos app and i want the UITextView to behave similarly like in tvos Movies app. I am specially interested in the focused appearence. Please have a look ate these two pictures.

Currently i am just adding background color to the textview when it is focused but how i can achieve this focused appearance in the attached images. here is my small code

override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
        super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)
        if context.previouslyFocusedView == lessonDescriptionTxt {

            coordinator.addCoordinatedAnimations({ () -> Void in
                self.lessonDescriptionTxt.layer.backgroundColor = UIColor.clearColor().CGColor

                }, completion: nil)
        }
        if context.nextFocusedView == lessonDescriptionTxt {

            coordinator.addCoordinatedAnimations({ () -> Void in
                self.lessonDescriptionTxt.layer.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.2).CGColor

                }, completion: nil)
        }
    }

Also if someone can suggest how i can achieve this MORE feature in the textView when there is more text. I also read this question Make UILabel focusable and tappable (tvOS) but that does not do the job for me.


回答1:


The "MORE" text appears only when the description can't fit in the space that's available. You should be able to measure the amount of space needed by text by using UIKit's -[NSAttributedString boundingRectWithSize:options:context:] method.



来源:https://stackoverflow.com/questions/34158882/tvos-uitextview-focus-appearance-like-movies-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!