Ios Xcode我的应用赢了';不能在iPad模拟器上工作,但可以在iPhone模拟器上工作
此代码当前以“警告可能导致癫痫发作”的消息开头,当您按下按钮时,屏幕将随机闪烁颜色。在主目录板中,我将didTapAdd操作拖到我制作的按钮上。它适用于所有iPhone模拟器,但当我在iPad上按下该消息时,什么都没有发生。这怎么可能Ios Xcode我的应用赢了';不能在iPad模拟器上工作,但可以在iPhone模拟器上工作,ios,swift,xcode,Ios,Swift,Xcode,此代码当前以“警告可能导致癫痫发作”的消息开头,当您按下按钮时,屏幕将随机闪烁颜色。在主目录板中,我将didTapAdd操作拖到我制作的按钮上。它适用于所有iPhone模拟器,但当我在iPad上按下该消息时,什么都没有发生。这怎么可能 import UIKit class ViewController: UIViewController { let colors: [UIColor] = [ .systemYellow, .systemGreen,
import UIKit
class ViewController: UIViewController {
let colors: [UIColor] = [
.systemYellow,
.systemGreen,
.systemPurple,
.systemPink,
.systemRed,
.systemBlue,
.systemOrange,
.magenta, .darkGray, .gray, .lightGray, .brown, .cyan
]
var label: UILabel?
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .clear
let label = UILabel()
view.addSubview(label)
label.text = "Warning. May cause a seizure."
label.textColor = UIColor.white
label.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
label.topAnchor.constraint(equalTo: view.topAnchor, constant: 200),
label.centerXAnchor.constraint(equalTo: view.centerXAnchor)
])
self.label = label /// assign self.label, so we can access it later
}
@IBAction func didTapButton() {
if let myLabel = label {
myLabel.removeFromSuperview()
self.label = nil /// set to nil, so we won't try to remove it again
}
let color1 = self.colors.randomElement()
let color2 = self.colors.randomElement()
self.view.layer.removeAllAnimations()
self.view.backgroundColor = color1 /// set to color1
UIView.animate(withDuration: 1/25, delay: 0, options: [.repeat, .autoreverse, .allowUserInteraction]) {
self.view.backgroundColor = .black
self.view.backgroundColor = color2// now animate to color2, reverse, then repeat
}
}
}
确保您添加了约束——它们很复杂,但这里有一个好的开始。但是,对于您的情况,简单的“对齐”约束应该可以正常工作
和容器中垂直方向的
对我来说很好:谢谢你的检查!你认为我做错了什么,或者你做了什么不同的事?它是有效的,你可以在消息的中间或者在消息的左边得到它,这取决于我正在使用的iPad。我能让它在屏幕上的任何地方都能工作吗..坦斯克!你增加了限制吗?你怎么做?你能告诉我吗?谢谢你这么多,但我很差劲,做不到:(你有TeamViewer吗?@ArashKalhori没有,但我有不和谐-aheze#3125谢谢,我会的,你知道如何使用flask吗?@ArashKalhori nope