现在在我的故事板上我有一个视图,我有一个连接到滚动视图的segue。我想这样做,以便在按下segue按钮后,故事板上第一个View上的东西(图像,标签,按钮)将转到Scrollview。
有没有办法当我进入滚动视图时,滚动视图将只是适合第一个视图中新输入信息所需的大小。
还有一种方法可以保存放入滚动视图的内容,以便用户可以添加到滚动视图以使其更大。如果我需要使用它来保存滚动视图信息,我的应用程序中有Firebase。
下面是我的两个视图控制器(我的滚动视图没有视图控制器,但如果需要,我可以创建一个)和我的故事板的屏幕截图,如果有帮助的话!
import UIKit
class PhotoShareViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var contentTextView: UITextView!
@IBOutlet weak var thatTextField: UITextField!
@IBOutlet weak var thisTextField: UITextField!
var presenter: PhotoShareModuleInterface!
var image: UIImage!
@IBAction func thisUploadPhoto(_ sender: Any) {
if thisTextField.text != "" && thatTextField.text != "" {
performSegue(withIdentifier: "segue", sender: nil)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let photoShareLabelViewController = segue.destination as! PhotoShareLabelViewController
photoShareLabelViewController.thisString = thisTextField.text!
photoShareLabelViewController.thatString = thatTextField.text!
photoShareLabelViewController.imageLoaded = image
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
imageView.image = image
}
override var prefersStatusBarHidden: Bool {
return true
}
@IBAction func didTapCancel(_ sender: AnyObject) {
presenter.cancel()
presenter.pop()
}
@IBAction func didTapDone(_ sender: AnyObject) {
guard let message = thatTextField.text, !message.isEmpty else {
return
}
guard let messageOne = thisTextField.text, !messageOne.isEmpty else {
return
}
presenter.finish(with: image, content:message)
presenter.dismiss()
}
}
extension PhotoShareViewController: PhotoShareViewInterface {
var controller: UIViewController? {
return self
}
}
import UIKit
class PhotoShareLabelViewController: UIViewController {
@IBOutlet weak var thisLabel: UILabel!
@IBOutlet weak var thatLabel: UILabel!
@IBOutlet weak var thisButton: UIButton!
@IBOutlet weak var thatButton: UIButton!
@IBOutlet weak var changedImage: UIImageView!
var thisCounter = 0
var thatCounter = 0
@IBAction func pressedDoneButtonLabel(_ sender: Any) {
print("done")
}
var presenter: PhotoShareModuleInterface!
var imageLoaded: UIImage!
@IBAction func pressedThisButton(_ sender: Any) {
thisCounter += 1
print(thisCounter)
}
@IBAction func pressedThatButton(_ sender: Any) {
thatCounter += 1
print(thatCounter)
}
var thisString = String()
var thatString = String()
@IBAction func pressedButtonDone(_ sender: Any) {
print("done")
}
// @IBAction func pressedButtonCancel(_ sender: Any) {
// print("cancel")
// }
override func viewDidLoad() {
super.viewDidLoad()
thisLabel.text = thisString
thisButton.setTitle(thisString, for: UIControlState.normal)
thatLabel.text = thatString
thatButton.setTitle(thatString, for: UIControlState.normal)
changedImage.image = imageLoaded
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
非常感谢!任何和所有的帮助表示赞赏!
答案 0 :(得分:1)
听起来你正在尝试做的事情几乎是针对UICollectionView
或UITableView
而做的。 UIScrollView
实际上是{{1}}的子类,有充分理由 - 内容会根据需要不断扩展。您需要将数据模型更改为您想要显示的数组,但这应该相当容易。
答案 1 :(得分:1)
我不完全确定你想要实现的目标,但如果我是正确的,你的照片数量会有动态变化吗?
如果是这种情况,我建议你看一下CollectionViews。这将为您处理滚动视图大小并帮助格式化。
考虑这两个链接 https://developer.apple.com/documentation/uikit/uicollectionview
很棒的教程: https://www.raywenderlich.com/136159/uicollectionview-tutorial-getting-started