Слайд-анимация для UILabel - PullRequest
0 голосов
/ 14 июня 2019

У меня есть эта функция, которая циклически перебирает массивы и меняет 2 метки. Как я могу сделать так, чтобы UILabels выходили справа и уходили налево?

func updateLabels() {
        self.myTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { (t) in
            self.titleLabel.text = self.titleArray[self.counter]
            self.textLabel.text = self.textArray[self.counter]
            self.counter += 1
            if self.counter == self.titleArray.count && self.counter == self.textArray.count {
                self.counter = 0
            }
        }
    }

1 Ответ

0 голосов
/ 14 июня 2019

Перемещение UILabel справа налево. Добавьте правильный constraints к вашей текстовой метке, и если вы хотите получить анимацию справа налево, установите текст Alignment вправо

func updateLabels() {

            self.myTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { (t) in
                self.titleLabel.text = self.titleArray[self.counter]
                self.textLabel.text = self.textArray[self.counter]
               DispatchQueue.main.async(execute: {
                UIView.animate(withDuration: 5.0, delay: 1, options: ([.curveLinear, .repeat]), animations: {() -> Void in
                    self.textLabel.center = CGPoint(x:0 - self.textLabel.bounds.size.width/2, y:self.textLabel.center.y)
                }, completion:  nil)
            })
                self.counter += 1
                if self.counter == self.titleArray.count && self.counter == 
                 self.textArray.count {
                    self.counter = 0
                }
            }
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...