繁体   English   中英

使用视图控制器的TabBar按钮在框架中添加滑动子视图

[英]Adding sliding subview in a frame using TabBar button of a View controller

我在视图控制器上有一个Tab-Bar按钮,我希望当用户按下该按钮时,从角落的一个子视图侧向显示并显示指定操作的按钮列表,并再次按下Tab栏按钮时,子视图应向后滑动然后消失。此子视图应显示在主视图的小框架上。 我如何完成这项任务?

将自定义操作添加到该按钮。 当用户按下按钮时,请检查按钮视图的原点是否在您的主视图范围内。 如果不是,则将其滑入,否则将其滑出。

我可能会做这样的事情:

//在viewDidLoad上调用它

-(void)createMenuButton {

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button addTarget:self action:@selector(toggleMenu) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];   
self.navigationItem.rightBarButtonItem = item;

}

//确保将menuView属性添加为self.view的子视图

-(void)toggleMenu {

if (CGRectContainsPoint(self.view.bounds, self.menuView.frame.origin)) {

    [UIView animateWithDuration:.35
                     animations:^{
                         CGRect rect = self.menuView.frame;
                         rect.origin.x -= self.menuView.frame.size.width;
                         self.menuView.frame = rect;
                     }];
} else {

    [UIView animateWithDuration:.35
                     animations:^{
                         CGRect rect = self.menuView.frame;
                         rect.origin.x += self.menuView.frame.size.width;
                         self.menuView.frame = rect;
                     }];
}

}

希望这可以帮助 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM