2016-03-14 3 views
0
viewDidLoad : 

topBarMenu = [[TopBarMenu alloc] initWithFrame:CGRectMake(0, 64, 1024, 0)]; 
    [self.view addSubview:topBarMenu]; 
    topBarMenu.clipsToBounds = YES; 


- (void)menuButton_TouchUpInside:(TopBarIcon *)sender 
{ 
    isTopBarMenuShown = !isTopBarMenuShown; 

    if (isTopBarMenuShown) { 

     [UIView animateWithDuration:1.5 animations:^{ 
      topBarMenu.frame = CGRectMake(0, 64, 1024, 600); 
           }]; 
    }else { 

     [UIView animateWithDuration:1.5 animations:^{ 
      topBarMenu.frame = CGRectMake(0, 64, 1024, 0); 
       }]; 
    } 
} 

В моем коде я хочу оживить показ и скрыть свое меню. Показ очень ступенчатый и не очень приятный. Скрытие немедленно удаляет экран без анимации. Как решить эту проблему ?Рамочная анимация не работает

ответ

0

Вы должны установить постоянный при использовании Autolayout и анимации. Итак, установите константу перед началом анимации. Таким образом, создайте выход с ограничением положения y.

topbaryposition.constant=0; (IBOutlet of Top position (Y postion of Topbar)) 


- (void)menuButton_TouchUpInside:(TopBarIcon *)sender 
{ 
    isTopBarMenuShown = !isTopBarMenuShown; 

    if (isTopBarMenuShown) { 

     [UIView animateWithDuration:1.5 animations:^{ 
      topBarMenu.frame = CGRectMake(0, 64, 1024, 600); 
           }]; 
    }else { 

     [UIView animateWithDuration:1.5 animations:^{ 
      topBarMenu.frame = CGRectMake(0, 64, 1024, 0); 
       }]; 
    } 
} 

Что-то подобное,

Edit: -

Я нашел ваш вопрос.

Ваш вопрос seeting кадра в другой, когда вы скрытие topbar.you установили только высоту, как но вы также должны установить у positioan как 0 ..

Что-то подобное,

topBarMenu.frame = CGRectMake(0, 0, 1024, 0); 




- (void)menuButton_TouchUpInside:(TopBarIcon *)sender 
{ 
    isTopBarMenuShown = !isTopBarMenuShown; 

    if (isTopBarMenuShown) { 

     [UIView animateWithDuration:1.5 animations:^{ 
      topBarMenu.frame = CGRectMake(0, 64, 1024, 600); 
           }]; 
    }else { 

     [UIView animateWithDuration:1.5 animations:^{ 
      topBarMenu.frame = CGRectMake(0, 0, 1024, 0); 
       }]; 
    } 
} 
+0

Спасибо, но это не решило мою проблему. Ehh. Найденное решение, я добавил [self.view layoutIfNeeded] и отлично работает. – hds

+0

ОК. поэтому вы решили свою проблему. хорошо. –

0

попробовать это

if (sideView.frame.origin.x >= 0) 
    { 
     [UIView animateKeyframesWithDuration:0.5 delay:0 options:UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{ 
      sideView.frame=CGRectMake(-400, 45, CGRectGetWidth(sideView.frame), CGRectGetHeight(sideView.frame)); 
     } completion:^(BOOL finished) { 

     }]; 
    } 

    else 
    { 
     [UIView animateKeyframesWithDuration:0.5 delay:0 options:UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{ 
      sideView.frame=CGRectMake(0, 45, CGRectGetWidth(sideView.frame), CGRectGetHeight(sideView.frame)); 
     } completion:^(BOOL finished) 
     { 

     }]; 
    } 
0

Я думаю, что набор кадров напрямую не очень хороший метод, я предлагаю изменить фрейм более подходящим. Такие как:

- (void)menuButton_TouchUpInside:(TopBarIcon *)sender 
{ 
    isTopBarMenuShown = !isTopBarMenuShown; 

    if (isTopBarMenuShown) { 

     [UIView animateWithDuration:1.5 animations:^{ 
      CGRect rect = topBarMenu.frame; 
      rect.size.height = 600.0f; 
      topBarMenu.frame = rect; 
      //topBarMenu.frame = CGRectMake(0, 64, 1024, 600); 
           }]; 
    } else { 

     [UIView animateWithDuration:1.5 animations:^{ 
      CGRect rect = topBarMenu.frame; 
      rect.size.height = 0.0f; 
      topBarMenu.frame = rect; 
      //topBarMenu.frame = CGRectMake(0, 64, 1024, 0); 
       }]; 
    } 
} 
Смежные вопросы