tvos:UITextView 焦点外观像电影应用 [英] tvos: UITextView focus appearance like movies App

查看:28
本文介绍了tvos:UITextView 焦点外观像电影应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 tvos 应用程序,我希望 UITextView 的行为类似于 tvos 电影应用程序中的行为.我对聚焦的外观特别感兴趣.请看看这两张图.

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)
        }
    }

此外,如果有人可以建议我如何在有更多文本时在 textView 中实现此 MORE 功能.我也阅读了这个问题 Make UILabel focusable and tappable (tvOS) 但这确实不要为我做这项工作.

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.

推荐答案

更多"文本仅在描述无法容纳可用空间时出现.您应该能够使用 UIKit 的 -[NSAttributedString boundingRectWithSize:options:context:] 方法来测量文本所需的空间量.

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.

这篇关于tvos:UITextView 焦点外观像电影应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆