0

Привет!

Пытаюсь сделать вращение UIImageView.

В viewDidLoad создаю картинку.

UIImage *radarImage = [UIImage imageNamed:@"newRadar.png"];
myRadarImage = [[UIImageView alloc] initWithFrame:CGRectMake(35, 80, 250, 250)];
myRadarImage.image = radarImage;
[self.myView addSubview:myRadarImage]; // Добавляю в myView - subview от self.view
myRadarImage.center = self.view.center;
[self goRotate];

И сам метод вращения:

- (void)goRotate {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:4.0f];
    [UIView setAnimationDelegate:self];
    myRadarImage.transform = CGAffineTransformMakeRotation((180.0f * M_PI) / 180.0f);
    [UIView commitAnimations];
}

Проблема в том, что анимация происходит мгновенно, а не за 4 секунды. Хотя если создать чистый проект - то все нормально работает. Пробовал [myRadarImage setTranslatesAutoresizingMaskIntoConstraints:NO];

2 ответа 2

2

Попробуйте вызвать [self goRotate]; в методе viewDidAppear

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self goRotate];
{
1
  • спасибо огромное!
    – michilly
    2 июн 2014 в 11:04
2

Вызывайте анимацию в wiewDidAppear

и перепишите метод анимации

- (void)goRotate {
    [UIView animateWithDuration:4.f
                     animations:^{
                     myRadarImage.transform = 
                              CGAffineTransformMakeRotation((180.0f * M_PI) / 180.0f);
                 }];
}

или более крутая анимация под iOS 7 с bounce эффектом (коэффициенты надо подбирать)

- (void)goRotate {
    [UIView animateWithDuration:4.f
                          delay:0
         usingSpringWithDamping:0.8f
          initialSpringVelocity:0.5f
                        options: UIViewAnimationOptionCurveEaseIn
                     animations:^ {
                         myRadarImage.transform = 
                              CGAffineTransformMakeRotation((180.0f * M_PI) / 180.0f);
                     } completion:nil];
}
1
  • спасибо ребята! всегда выручаете:)
    – michilly
    2 июн 2014 в 11:04

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.