gpt4 book ai didi

ios - UIButton 图像在动画开始淡入之前出现在启动屏幕中

转载 作者:行者123 更新时间:2023-11-30 13:54:15 25 4
gpt4 key购买 nike

所以我在后台播放了一个视频,并有两个淡入的按钮图像。两者都工作正常,但是在模拟器上,当我启动应用程序时,我在白色屏幕上看到按钮图像,然后它开始播放视频和动画。我还在每个图像的主 Storyboard中将 alpha 设置为 0。不确定这是模拟器/启动屏幕故障还是我的代码。我的代码如下,感谢任何帮助。谢谢!

import UIKit
import Parse
import MediaPlayer


class ViewController: UIViewController {
@IBOutlet var loginAlpha: UIButton!
@IBOutlet var signupAlpha: UIButton!


var avPlayer: AVPlayer!
var avPlayerLayer: AVPlayerLayer!
var paused: Bool = false

override func viewDidLoad() {
super.viewDidLoad()

// code for background video

let theURL = NSBundle.mainBundle().URLForResource("test", withExtension: "mp4")

avPlayer = AVPlayer(URL: theURL!)
avPlayerLayer = AVPlayerLayer(player: avPlayer)
avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
avPlayer.volume = 0
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEnd.None

avPlayerLayer.frame = view.layer.bounds
view.backgroundColor = UIColor.clearColor();
view.layer.insertSublayer(avPlayerLayer, atIndex: 0)

NSNotificationCenter.defaultCenter().addObserver(self,
selector: "playerItemDidReachEnd:",
name: AVPlayerItemDidPlayToEndTimeNotification,
object: avPlayer.currentItem)
}

func playerItemDidReachEnd(notification: NSNotification) {
let p: AVPlayerItem = notification.object as! AVPlayerItem
p.seekToTime(kCMTimeZero)
}

override func viewDidAppear(animated: Bool) {
signupAlpha.alpha = 0
loginAlpha.alpha = 0

UIView.animateWithDuration(1.5, delay: 1.0, options: [], animations: { () -> Void in
self.signupAlpha.alpha = 1.0
self.loginAlpha.alpha = 1.0

}, completion: nil)

avPlayer.play()
paused = false
}

override func viewDidDisappear(animated: Bool) {
avPlayer.pause()
paused = true
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

最佳答案

我找到了一个简单的解决方案:

viewDidLoad上(您也可以在 Storyboard上设置它。)

    loginAlpha.hidden = true
signupAlpha.hidden = true

以及viewDidAppear

    signupAlpha.alpha = 0
loginAlpha.alpha = 0
loginAlpha.hidden = false
signupAlpha.hidden = false

关于ios - UIButton 图像在动画开始淡入之前出现在启动屏幕中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33850411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com