Неожиданное поведение после кнопки «Назад» - PullRequest
0 голосов
/ 12 октября 2018

У меня есть этот текст на экране входа в систему:

enter image description here

подчеркнутый текст кликабелен.Я нажимаю Условия и положения:

enter image description here

И я отправляюсь на этот экран.Теперь, после нажатия «Назад»:

1) Текст пропал:

enter image description here

2) Появится заполнитель навигационной панели:

enter image description here

Похоже, что появление этого заполнителя каким-то образом сужает представление.

"Перед" рис. Экрана:

enter image description here

«После» снимок экрана:

enter image description here

Также - что такоелучший способ убедиться, что две кнопки входа одинакового размера (высота, ширина) и расположены близко друг к другу?Я попробовал это:

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

1 Ответ

0 голосов
/ 12 октября 2018

Итак, вы использовали segue для вызова другого viewController с помощью раскадровки.Но похоже, что вы использовали Present Modally segue для вызова другого viewController.Вам нужно позвонить Показать (Push) .Вы можете прочитать больше о segue здесь: https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html Чтобы решить вашу проблему, просто измените свой вид sege на Показывать как это в вашей раскадровке

Change

...