Closed yujia917 closed 7 years ago
我测试的时候也遇到同样的问题,查了一源代码,回调的时候因为调用了[weakView currentViewController] 这个方法,而currentViewController方法返回的的viewController 并不是你调用popMenu的所在的页面的那个controller。而是viewController(就是rootViewController),代理执行方法也只能在viewController里调用。测试了一下午才发现这个问题。
同样的,else { NSLog(@"不在同一个控制器"); } 源码这一段,我感觉可能是套错括号了。因为在你调不到点击事件代理方法的时候,就是viewcontroller错误的问题。所以这层括号应该是上一个if的else。这是我自己的猜测,不知道对不对呢。。。。
popMenu是通过tabBarController打开的,[weakView currentViewController] 返回的是当前所在的viewController,而不是tabBarController. 假如tabBarController有五个viewController, 同样的delegate要在每个controller里都写一遍?
这个楼主有什么好建议或是修改计划?
我的做法:在viewController里遵循PopMenu的协议,在viewcontroller里执行代理方法。只能临时解决。
@yujia917 @Shin1122 代理不执行问题已经修复 原因是因为PopMenuView是单利模式,因此在多个ViewController里遵循delegate都会执行delegate里的方法。
public func popMenuView(popMenuView: HyPopMenuView!, didSelectItemAtIndex index: UInt) { }
点击menu button之后,上面的delegate没被调用, 不知道什么问题。Debug的时候,显示下面方法里的这个if条件不满足: if ([weakView.delegate respondsToSelector:@selector(popMenuView:didSelectItemAtIndex:)])
(void)selectedFunc:(PopMenuButton_)sender { _weak HyPopMenuView weakView = self; [_dataSource enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL* _Nonnull stop) { PopMenuModel* model = obj; PopMenuButton* button = (id)model.customView; if (sender == button) { [sender selectdAnimation]; } else { [button cancelAnimation]; } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [model performSelector:@selector(_obj)]; }); }]; NSUInteger idx = [_dataSource indexOfObject:sender.model]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (weakView.delegate) { if ([weakView.delegate isKindOfClass:[[weakView currentViewController] class]]) { if ([weakView.delegate respondsToSelector:@selector(popMenuView:didSelectItemAtIndex:)]) { [weakView.delegate popMenuView:weakView didSelectItemAtIndex:idx]; } } else { NSLog(@"不在同一个控制器"); } } }); [UIView animateWithDuration:0.2 animations:^{ weakView.bottomView.backgroundColor = [UIColor clearColor]; weakView.disappearButton.transform = CGAffineTransformMakeRotation(0); [weakView.disappearButton setAlpha:0.1f]; }];
[UIView animateKeyframesWithDuration:0.5 delay:0.2f options:0 animations:^{ weakView.backgroundView.alpha = 0.0; } completion:^(BOOL finished) {
}