我想为 iPhone 使用弹出视图。我找到了一个 3rd 方库,作者说它的一些方法正在使用私有方法。(提交到应用商店时会导致问题)
但我看不出他的代码中在哪里使用了私有方法。
你能发现它们吗?
[barButtonItem performSelector:@selector(view)] 被认为是调用私有方法?
https://github.com/sonsongithub/PopupView/blob/master/SNPopupView%2BUsingPrivateMethod.m
- (void)showFromBarButtonItem:(UIBarButtonItem*)barButtonItem inView:(UIView*)inView animated:(BOOL)animated {
if(![barButtonItem respondsToSelector:@selector(view)]) {
// error
return;
}
UIView *targetView = (UIView *)[barButtonItem performSelector:@selector(view)];
UIView *targetSuperview = [targetView superview];
BOOL isOnNavigationBar = YES;
if ([targetSuperview isKindOfClass:[UINavigationBar class]]) {
isOnNavigationBar = YES;
}
else if ([targetSuperview isKindOfClass:[UIToolbar class]]) {
isOnNavigationBar = NO;
}
else {
// error
return;
}
CGRect rect = [targetSuperview convertRect:targetView.frame toView:inView];
CGPoint p;
p.x = rect.origin.x + (int)rect.size.width/2;
if (isOnNavigationBar)
p.y = rect.origin.y + rect.size.height + BAR_BUTTON_ITEM_UPPER_MARGIN;
else
p.y = rect.origin.y - BAR_BUTTON_ITEM_BOTTOM_MARGIN;
[self showAtPoint:p inView:inView animated:animated];
}