IOS - анимация движения метки или изображения
Как я могу оживить движение метки или изображения? Я просто хотел бы сделать медленный переход от одного места на экране к другому (ничего необычного).
Ответы
Ответ 1
Вы ищете методы -beginAnimations:context:
и -commitAnimations
на UIView.
Вкратце, вы делаете что-то вроде:
[UIView beginAnimations:nil context:NULL]; // animate the following:
myLabel.frame = newRect; // move to new location
[UIView setAnimationDuration:0.3];
[UIView commitAnimations];
Ответ 2
Для ios4 и более поздних версий не следует использовать beginAnimations:context
и commitAnimations
, так как они обескуражены в documentation.
Вместо этого вы должны использовать один из методов на основе блоков.
Приведенный выше пример будет выглядеть следующим образом:
[UIView animateWithDuration:0.3 animations:^{ // animate the following:
myLabel.frame = newRect; // move to new location
}];
Ответ 3
Вот пример с UILabel
- анимация сдвигает ярлык слева в 0,3 секунды.
// Save the original configuration.
CGRect initialFrame = label.frame;
// Displace the label so it hidden outside of the screen before animation starts.
CGRect displacedFrame = initialFrame;
displacedFrame.origin.x = -100;
label.frame = displacedFrame;
// Restore label initial position during animation.
[UIView animateWithDuration:0.3 animations:^{
label.frame = initialFrame;
}];