Tôi cần phải làm điều tương tự và vì vậy tôi đã kết thúc cuộc tranh luận UINavigationBar với phương thức withEvent và kiểm tra toạ độ y của liên lạc trước khi gọi phương thức gốc.
Điều này có nghĩa là khi chạm quá gần nút mà tôi đang sử dụng trong Điều hướng, tôi có thể hủy nó.
Ex: Các nút quay lại hầu như luôn chiếm được sự kiện cảm ứng thay cho nút "đầu tiên"
Đây là loại của tôi:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)sTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
float maxY = 0;
for (UITouch *touch in touches) {
float touchY = [touch locationInView:self].y;
if ([touch locationInView:self].y > maxY) maxY = touchY;
}
NSLog(@"swizzlelichious bar touchY %f", maxY);
if (maxY < 35)
[self sTouchesEnded:touches withEvent:event];
else
[self touchesCancelled:touches withEvent:event];
}
- (void)sTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
float maxY = 0;
for (UITouch *touch in touches) {
float touchY = [touch locationInView:self].y;
if ([touch locationInView:self].y > maxY) maxY = touchY;
}
NSLog(@"swizzlelichious bar touchY %f", maxY);
if (maxY < 35)
[self sTouchesBegan:touches withEvent:event];
else
[self touchesCancelled:touches withEvent:event];
}
Việc thực hiện sự gian lận bởi Mike Ash từ CocoaDev
void Swizzle(Class c, SEL orig, SEL new)
{
Method origMethod = class_getInstanceMethod(c, orig);
Method newMethod = class_getInstanceMethod(c, new);
if(class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}
Và hàm gọi hàm swizzle
Tôi không biết liệu Apple có đồng ý với điều này hay không, nó có thể vi phạm nguyên tắc UI của họ, tôi sẽ cố cập nhật bài đăng nếu sau khi tôi gửi ứng dụng đến cửa hàng ứng dụng.
tôi có cùng một sự cố ngay bây giờ, bạn có tìm thấy giải pháp không? –
nope xin lỗi ... Tôi thấy rằng lỗi trong nhiều ứng dụng ...: o –