0

我的ipad应用程序中有一个侧边栏,当有这个方法 toggleMenu 正在执行动画但是当我从另一个视图控制器调用该方法时它不执行动画。该方法运行良好但没有动画

方法是

-(IBAction)toggleMenu
{

[UIView beginAnimations:@"Menu Slide" context:nil];
[UIView setAnimationDuration:0.2];

if(self.contentView.frame.origin.x == 0) //Menu is hidden
{

    NSLog(@"show menu");

    CGRect newFrame = CGRectOffset(self.contentView.frame, self.menuView.frame.size.width, 0.0);
    self.contentView.frame = newFrame;

}
else //Menu is shown
{

    NSLog(@"hide menu");

    [menuTableView reloadData];
    CGRect newFrame = CGRectOffset(self.contentView.frame, -(self.menuView.frame.size.width), 0.0);
    self.contentView.frame = newFrame;

}

[UIView commitAnimations];

}
4

1 回答 1

1

试试这个,当你想要动画时,你必须从另一个视图控制器发送通知..

  [[NSNotificationCenter defaultCenter] postNotificationName:@"animationstart"        object:nil];

在滑动菜单视图控制器中

  -(void)viewDidLoad

{
 [[NSNotificationCenter defaultCenter] removeObserver:self];
 [[NSNotificationCenter defaultCenter] addObserver:self    selector:@selector(toggleMenu) name:@"animationstart" object:nil];

}

- (IBAction)toggleMenu
{
  [UIView beginAnimations:@"Menu Slide" context:nil];
  [UIView setAnimationDuration:0.2];

if(self.contentView.frame.origin.x == 0) //Menu is hidden
{

NSLog(@"show menu");

CGRect newFrame = CGRectOffset(self.contentView.frame, self.menuView.frame.size.width, 0.0);
self.contentView.frame = newFrame;

 }
 else //Menu is shown
 {

NSLog(@"hide menu");

[menuTableView reloadData];
CGRect newFrame = CGRectOffset(self.contentView.frame, -   (self.menuView.frame.size.width), 0.0);
self.contentView.frame = newFrame;

}

[UIView commitAnimations];


}
于 2013-06-13T13:17:32.243 回答