맞춤 UI보기의 제약 조건을 업데이트하는 방법이 궁금합니다. 확실히 내 코드의 오류입니다. 나는 사전에 사과한다, 나는 Swift의 초보자에 불과하다.Swift Playgrounds 프로그램의 프로그래밍 제약 조건 문제
public class NoteCardView:UIView {
@IBInspectable var contentView = UIButton(frame: .zero)
@IBInspectable var delegate: MainViewController?
var leftAnchor: NSLayoutXAxisAnchor
var bottomAnchor: NSLayoutYAxisAnchor
override public func updateConstraints() {
contentView.translatesAutoresizingMaskIntoConstraints = false
contentView.layer.masksToBounds = true
contentView.layer.cornerRadius = 6
contentView.widthAnchor.constraint(equalToConstant: 75).isActive = true
contentView.heightAnchor.constraint(equalToConstant: 100).isActive = true
leftAnchor = contentView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: positionX).isActive = true
bottomAnchor = contentView.bottomAnchor.constraint(equalTo: (delegate?.view.bottomAnchor)!, constant: positionY).isActive = true
titleLabel.textAlignment = .center
titleLabel.text = note
contentView.addSubview(titleLabel)
super.updateConstraints()
}
class MainViewController: UIViewController {
override func viewDidLoad() {
// Trying to implement updated constraints to the NoteCardView here.
}
}
또한 TapGestureRecognizer와 관련없는이 문제가 있습니다. 나는이 개념에도 익숙하지 않다.
public class NoteCard:UIView {
internal var titleLabelTapGestureRecognizer: UITapGestureRecognizer?
internal func commonInit() {
self.titleLabelTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTitleLabelTap(UITapGestureRecognizer)))
}
internal func handleTitleLabelTap(_ recognizer:UITapGestureRecognizer) {
self.delegate?.noteCardViewTitleLabelDidRecieveTap(self)
}
}
도움을 주셔서 감사합니다.
그 밖의 것이 없다면 왼쪽 앵커가 콘텐츠보기와 그 자체 사이에 있으며 이는 의미가 없습니다. 또한 일반적으로 제약 조건을 설정하기 전에 계층에보기를 추가해야합니다. 제약 조건 기반 오류 메시지가 표시되면 정확한 메시지를 공유하십시오 (앞서 언급 한 제약 조건을 수정 한 후). – Rob