我的登录屏幕上有以下文字:
带下划线的文本是可单击的。我点击条款和条件:
然后我被发送到此屏幕。现在,点击“返回”后:
1)文本不见了:
2)出现导航栏占位符:
此占位符的外观似乎在某种程度上缩小了视图。
屏幕上的“之前”图片:
屏幕上的“之后”图片:
而且-确保两个登录按钮的大小(高度,宽度)相同且彼此靠近的最佳方法是什么?我尝试过:
FacebookSignInButton.frame = CGRect(x: self.view.frame.width/2, y: self.view.frame.height/2, width: GoogleSignInButton.frame.width, height: GoogleSignInButton.frame.height)
不起作用(您现在看到的视图正在使用此代码行)
查看条款和条件的代码:
class PolicyViewController: UIViewController
{
var policy = PolicyModel(policy: "")
{
didSet { updateViews() }
}
@IBOutlet var HeaderLabel: UILabel!
@IBOutlet var TextToDisplay: UITextView!
override func viewDidLoad()
{
super.viewDidLoad()
self.navigationController?.setNavigationBarHidden(false, animated: true)
updateViews()
Constants.logger.debug("PolicyViewController loaded")
}
private func updateViews()
{
guard isViewLoaded else { return }
HeaderLabel.text = policy.title
TextToDisplay.text = policy.body
}
}
主登录屏幕中的代码(可单击文本):
@IBAction func AcceptanceTextTapped(_ sender: UITapGestureRecognizer)
{
let text = (AcceptanceText.text)!
let termsRange = (text as NSString).range(of: LocalizationStrings.Login.TERMS_AND_CONDITIONS)
let privacyRange = (text as NSString).range(of: LocalizationStrings.Login.PRIVACY_POLICY)
if sender.didTapAttributedTextInLabel(label: AcceptanceText, inRange: termsRange)
{
performSegue(withIdentifier: "segue_to_tc", sender: self)
}
else if sender.didTapAttributedTextInLabel(label: AcceptanceText, inRange: privacyRange)
{
performSegue(withIdentifier: "segue_to_p", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
switch (segue.identifier ?? "", segue.destination)
{
case ("segue_to_tc", let destination as PolicyViewController):
destination.policy = PolicyModel(policy: "TS")
case ("segue_to_p", let destination as PolicyViewController):
destination.policy = PolicyModel(policy: "PP")
case ("segue_facebook_login", let destination as UITabBarController) :
prepareTabBarUI(tabBar: destination)
default: super.prepare(for: segue, sender: sender)
}
}
// This extension serves to be able to identify tapping on the text of Acceptance and Privacy Policy
extension UITapGestureRecognizer
{
func didTapAttributedTextInLabel(label: UILabel, inRange targetRange: NSRange) -> Bool
{
// Create instances of NSLayoutManager, NSTextContainer and NSTextStorage
let layoutManager = NSLayoutManager()
let textContainer = NSTextContainer()
let textStorage = NSTextStorage(attributedString: label.attributedText!)
// Configure layoutManager and textStorage
layoutManager.addTextContainer(textContainer)
textStorage.addLayoutManager(layoutManager)
// Configure textContainer
textContainer.lineFragmentPadding = 0.0
textContainer.lineBreakMode = label.lineBreakMode
textContainer.maximumNumberOfLines = label.numberOfLines
let labelSize = label.bounds.size
textContainer.size = labelSize
// Find the tapped character location and compare it to the specified range
let locationOfTouchInLabel = self.location(in: label)
let textBoundingBox = layoutManager.usedRect(for: textContainer)
let textContainerOffset = CGPoint( x: (labelSize.width - textBoundingBox.size.width) * 0.5 - textBoundingBox.origin.x,
y: (labelSize.height - textBoundingBox.size.height) * 0.5 - textBoundingBox.origin.y);
let locationOfTouchInTextContainer = CGPoint(x: locationOfTouchInLabel.x - textContainerOffset.x,
y: locationOfTouchInLabel.y - textContainerOffset.y);
let indexOfCharacter = layoutManager.characterIndex(for: locationOfTouchInTextContainer, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
return NSLocationInRange(indexOfCharacter, targetRange)
}
}
编辑:
故事板图片:
答案 0 :(得分:0)
因此,您使用segue使用情节提要调用了另一个viewController。但是看来您使用模态呈现 segue来调用另一个viewController。您需要调用的是显示(推送)。您可以在这里阅读更多有关segue的信息:https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html 要解决您的问题,只需将您的segue类型更改为在情节提要中显示为