bạn muốn tạo ra một phong tục UIView
với tất cả các đối tượng được tôn trọng cần thiết, từ viewDidLoad Kiểm Soát Tài Chính của bạn(), bạn sẽ giấu nó.
customView.hidden = true
Bất cứ khi nào người dùng của bạn muốn thực hiện một số hành động hoặc công việc, bạn thôi ẩn nó và khi người dùng hoàn thành sau đó giấu nó một lần nữa hoặc loại bỏ từ SuperView.
customView.hidden = false
Dưới đây có một số mã để giúp bạn bắt đầu
private var customView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
customView.hidden = true
}
private func loadCustomViewIntoController() {
let customViewFrame = CGRect(x: 0, y: 0, witdh: view.frame.width, height: view.frame.height - 200)
customView = UIView(frame: customViewFrame)
view.addSubview(customView)
customView.hidden = false
// any other objects should be tied to this view as superView
// for example adding this okayButton
let okayButtonFrame = CGRect(x: 40, y: 100, width: 50, height: 50)
let okayButton = UIButton(frame: okayButtonFrame)
// here we are adding the button its superView
customView.addSubview(okayButton)
okayButton.addTarget(self, action: #selector(self.didPressButtonFromCustomView:), forControlEvents:.TouchUpInside)
}
func didPressButtonFromCustomView(sender:UIButton) {
// do whatever you want
// make view disappears again, or remove from its superview
}
@IBAction func rateButton(sender:UIBarButtonItem) {
// this barButton is located at the top of your tableview navigation bar
// when it pressed make sure you remove any other activities that were on the screen, for example dismiss a keyboard
loadCustomViewIntoController()
}
Check it out github project này, Nó đóng cửa để được sản xuất sẵn sàng, nó mang lại cho bạn một cách tốt hơn để đối phó (hiện tại và bỏ qua) với UIViews
Nếu bạn chỉ muốn tên của người chơi, hãy sử dụng UIAlertController
cont aining một textfield
Tôi đã làm việc trên tùy chọn đó, vấn đề là trên bảng câu chuyện là loại khó thực hiện kể từ khi tôi làm việc với một tableview và không có nơi để đặt "UIView". Hoặc ít nhất tôi không biết cách làm điều đó. Nếu tôi thêm chế độ xem vào đầu, đó là chế độ xem cho tiêu đề hoặc ở dưới cùng là chế độ xem cho chân trang. Tôi sẽ thêm ảnh chụp màn hình vào bài đăng gốc của ý tôi. –
bạn không cần phải kéo UIView trên đầu trang của tableview ... bạn có thể tạo UIView qua mã bạn muốn xem một ví dụ? – Lamar
Xin vui lòng .. Tôi đã bao quanh đầu của tôi xung quanh này. –