Swift 在tvOS 12的TVUIKit中使用TVPosterImage
TVOS12有一个新的框架,它引入了锁定视图。我感兴趣的课程是,基本上是这样设计的: Swift 4.2Swift 在tvOS 12的TVUIKit中使用TVPosterImage,swift,uiview,uiimageview,tvos,uicontrol,Swift,Uiview,Uiimageview,Tvos,Uicontrol,TVOS12有一个新的框架,它引入了锁定视图。我感兴趣的课程是,基本上是这样设计的: Swift 4.2 open class TVPosterView : TVLockupView { // One may use UIControl to implement it in iOS public init(image: UIImage?) open var image: UIImage? // default is nil open var title: String?
open class TVPosterView : TVLockupView { // One may use UIControl to implement it in iOS
public init(image: UIImage?)
open var image: UIImage? // default is nil
open var title: String?
open var subtitle: String?
}
import UIKit
import TVUIKit
class SecondViewController: UIViewController {
var myPoster = TVPosterView()
var myMonogram = TVMonogramView()
override func viewDidLoad() {
super.viewDidLoad()
myPoster.frame = CGRect(x: 100, y: 100, width: 550, height: 625)
myPoster.image = UIImage(named: "image1.png")
myPoster.imageView.masksFocusEffectToContents = true
myPoster.title = "Poster"
myPoster.subtitle = "This is the poster subtitle"
self.view.addSubview(myPoster)
var myName = PersonNameComponents()
myName.givenName = "Michele"
myName.familyName = "Dall'Agata"
myMonogram.frame = CGRect(x: 700, y: 100, width: 500, height: 475)
myMonogram.image = UIImage(named: "image2.png")
myMonogram.title = "Monogram"
myMonogram.subtitle = "This is the Monogram subtitle"
myMonogram.personNameComponents = myName
self.view.addSubview(myMonogram)
print(myMonogram.personNameComponents)
}
}
在我的故事板中,我添加了UIView元素,并且正确地(至少我希望如此。昨天IB代理不断崩溃!)在Identity Inspector中将其类更改为TVPosterView。然后在我的UIViewController中,我定义了:
@IBOutlet var aPosterView: TVPosterView!
override func viewDidLoad() {
super.viewDidLoad()
if let myIcon = UIImage(named: "icon.png") {
self.aPosterView = TVPosterView(image: myIcon)
self.aPosterView.title = "My Title"
self.aPosterView.subtitle = "A Sub Title"
}
else {
print("ERROR: I couldn't load the icon!")
}
}
}
它编译时没有任何警告。当我运行它时,它只显示UIView白色背景,没有任何变化。我做了一些测试,试图添加UIImageView,但都没有结果(当然,当我将UIImageView的映像设置为self.aPosterView.image时,它们是不确定的)
我远非专家,我几周前才开始学习。你知道我错过了什么吗?我认为这个概念是,一旦我开始上课,这个框架就负责显示带有(可选)标题和字幕的海报,还负责所有漂亮的动画 最终我成功地使它以编程方式工作。我测试了TVPosterView和TVPosterView(基本上是一个圆形按钮)。以下代码适用于tvOS 12 beta 5上的Xcode 10 beta 5: Swift 4.2
open class TVPosterView : TVLockupView { // One may use UIControl to implement it in iOS
public init(image: UIImage?)
open var image: UIImage? // default is nil
open var title: String?
open var subtitle: String?
}
import UIKit
import TVUIKit
class SecondViewController: UIViewController {
var myPoster = TVPosterView()
var myMonogram = TVMonogramView()
override func viewDidLoad() {
super.viewDidLoad()
myPoster.frame = CGRect(x: 100, y: 100, width: 550, height: 625)
myPoster.image = UIImage(named: "image1.png")
myPoster.imageView.masksFocusEffectToContents = true
myPoster.title = "Poster"
myPoster.subtitle = "This is the poster subtitle"
self.view.addSubview(myPoster)
var myName = PersonNameComponents()
myName.givenName = "Michele"
myName.familyName = "Dall'Agata"
myMonogram.frame = CGRect(x: 700, y: 100, width: 500, height: 475)
myMonogram.image = UIImage(named: "image2.png")
myMonogram.title = "Monogram"
myMonogram.subtitle = "This is the Monogram subtitle"
myMonogram.personNameComponents = myName
self.view.addSubview(myMonogram)
print(myMonogram.personNameComponents)
}
}
不过,我没有用ScaleSpectFit缩放海报的图像。另外,我的第一张图像是透明的,只选择了一个完全适合方形图像加上标题的框架大小(因此不需要侧面匹配),发光效果在角落变得透明。否则,整个图像是不透明的,使用了它自己的(相当小的)圆角。最终我设法使它以编程方式工作。我测试了TVPosterView和TVPosterView(基本上是一个圆形按钮)。以下代码适用于tvOS 12 beta 5上的Xcode 10 beta 5: Swift 4.2
open class TVPosterView : TVLockupView { // One may use UIControl to implement it in iOS
public init(image: UIImage?)
open var image: UIImage? // default is nil
open var title: String?
open var subtitle: String?
}
import UIKit
import TVUIKit
class SecondViewController: UIViewController {
var myPoster = TVPosterView()
var myMonogram = TVMonogramView()
override func viewDidLoad() {
super.viewDidLoad()
myPoster.frame = CGRect(x: 100, y: 100, width: 550, height: 625)
myPoster.image = UIImage(named: "image1.png")
myPoster.imageView.masksFocusEffectToContents = true
myPoster.title = "Poster"
myPoster.subtitle = "This is the poster subtitle"
self.view.addSubview(myPoster)
var myName = PersonNameComponents()
myName.givenName = "Michele"
myName.familyName = "Dall'Agata"
myMonogram.frame = CGRect(x: 700, y: 100, width: 500, height: 475)
myMonogram.image = UIImage(named: "image2.png")
myMonogram.title = "Monogram"
myMonogram.subtitle = "This is the Monogram subtitle"
myMonogram.personNameComponents = myName
self.view.addSubview(myMonogram)
print(myMonogram.personNameComponents)
}
}
不过,我没有用ScaleSpectFit缩放海报的图像。另外,我的第一张图像是透明的,只选择了一个完全适合方形图像加上标题的框架大小(因此不需要侧面匹配),发光效果在角落变得透明。否则,整个图像是不透明的,使用它自己的(相当小的)圆角