构建应用程序后不显示 UI 保存按钮
Posted
技术标签:
【中文标题】构建应用程序后不显示 UI 保存按钮【英文标题】:UIsavebutton doesnt show after built the app 【发布时间】:2020-02-14 10:44:57 【问题描述】:这是一个壁纸应用,所以屏幕上有保存按钮,UIButton 应该保存当前显示给用户的图像。所以我已经编写了这段代码并识别了 UIButton 然后当我开始构建应用程序时,按钮没有显示出来......
这是我的代码
class ViewController: UIViewController
// app parameters
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var saveButton: UIButton!
//when tapped
@IBAction func saveButtonTapped(_ sender: UIButton)
let success = saveImage(image: imageArray[0])
print("Did \(success ? "" : "not ")store image successfully")
//scroll view
let scrollView: UIScrollView =
let scroll = UIScrollView()
scroll.isPagingEnabled = true
scroll.showsVerticalScrollIndicator = false
scroll.showsHorizontalScrollIndicator = false
scroll.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
return scroll
()
//setup images
func setupImages(_ images: [UIImage])
for i in 0..<images.count
let imageView = UIImageView()
imageView.image = images[i]
let xPosition = UIScreen.main.bounds.width * CGFloat(i)
imageView.frame = CGRect(x: xPosition, y: 0, width: scrollView.frame.width, height: scrollView.frame.height)
imageView.contentMode = .scaleAspectFit
scrollView.contentSize.width = scrollView.frame.width * CGFloat(i + 1)
scrollView.addSubview(imageView)
//image array
var imageArray = [UIImage]()
//save image
func saveImage(image: UIImage) -> Bool
guard let data = image.jpegData(compressionQuality: 1) ?? image.pngData() else
return false
guard let directory = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) as NSURL else
return false
do
try data.write(to: directory.appendingPathComponent("fileName.png")!)
return true
catch
print(error.localizedDescription)
return false
//did load
override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view.
//imageArray
view.addSubview(scrollView)
imageArray = [#imageLiteral(resourceName: "6"),#imageLiteral(resourceName: "9"),#imageLiteral(resourceName: "3")]
setupImages(imageArray)
【问题讨论】:
试试 savebutton.bringtofront,你能展示你的故事板拱门吗 确保你的按钮在滚动视图的前面。 【参考方案1】:试试这个!
override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view.
//imageArray
view.addSubview(scrollView)
imageArray = [#imageLiteral(resourceName: "6"),#imageLiteral(resourceName: "9"),#imageLiteral(resourceName: "3")]
setupImages(imageArray)
scrollView.addSubview(saveButton)
【讨论】:
一条消息出来,线程 1:致命错误:在隐式展开可选值时意外发现 nil以上是关于构建应用程序后不显示 UI 保存按钮的主要内容,如果未能解决你的问题,请参考以下文章
SharedPreferences 将按钮更改保存为单击后不可见
在 appium 中启动检查器后不显示 android 的 UI 内容
Vaadin 7 在执行后台线程后不刷新 UI(仅当它需要超过 5 分钟时)