1
Как оживить изменение ширины при сохранении ориентации в центре?Анимация Ширина UILabel с фиксированным центром
В настоящее время, когда я это делаю, он не растет из центра.
self.textLabel = UILabel()
self.textLabel.frame = CGRectMake(0, 0, Globals.voterTextLabel, Globals.voterTextLabel)
self.textLabel.center = CGPointMake(self.view.frame.width/2, self.view.frame.height/2)
self.textLabel.text = "VS"
self.textLabel.layer.cornerRadius = Globals.voterTextLabel/2
self.textLabel.layer.masksToBounds = true
self.textLabel.clipsToBounds = true
self.textLabel.backgroundColor = UIColor.whiteColor()
self.textLabel.textColor = Colors.voterTextLabel
self.textLabel.textAlignment = .Center
self.textLabel.autoresizingMask = .FlexibleWidth
self.view.addSubview(self.textLabel)
UIView.animateWithDuration(2, animations: {
self.textLabel.frame.size.width = 150
self.textLabel.center.x = self.view.frame.width/2
}, completion: nil)
вопрос имеет «быстрый» тег. Если OP явно не упоминает, что они также принимают ответы Objective-C (и это не так), лучше отправить ответ в Swift. Спасибо. :) – Moritz
@ EricD. Извините за код цели-c. Обновлен мой ответ с помощью фрагмента кода Swift. –
Нет проблем. Спасибо за обновление. – Moritz