У меня есть этот текст на экране входа в систему:
![enter image description here](https://i.stack.imgur.com/z21Zu.jpg)
подчеркнутый текст кликабелен.Я нажимаю Условия и положения:
![enter image description here](https://i.stack.imgur.com/OS7ds.jpg)
И я отправляюсь на этот экран.Теперь, после нажатия «Назад»:
1) Текст пропал:
![enter image description here](https://i.stack.imgur.com/DnzbY.jpg)
2) Появится заполнитель навигационной панели:
![enter image description here](https://i.stack.imgur.com/2GKxj.jpg)
Похоже, что появление этого заполнителя каким-то образом сужает представление.
"Перед" рис. Экрана:
![enter image description here](https://i.stack.imgur.com/XFqyS.jpg)
«После» снимок экрана:
![enter image description here](https://i.stack.imgur.com/yvZX2.jpg)
Также - что такоелучший способ убедиться, что две кнопки входа одинакового размера (высота, ширина) и расположены близко друг к другу?Я попробовал это:
FacebookSignInButton.frame = CGRect(x: self.view.frame.width/2, y: self.view.frame.height/2, width: GoogleSignInButton.frame.width, height: GoogleSignInButton.frame.height)
, который не работал (вид, который вы видите сейчас, использует эту строку кода)
Код для просмотра T & C:
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)
}
}
РЕДАКТИРОВАТЬ:
Изображение раскадровки:
![enter image description here](https://i.stack.imgur.com/6qctv.jpg)