प्रतीक UIViewAlertForUnsatisfiableConstraints
वास्तव में एक समारोह है।
यह निजी है, इसलिए आप इसे प्रतिस्थापित नहीं कर सकते हैं।
लेकिन इसे निजी विधि -[UIView engine:willBreakConstraint:dueToMutuallyExclusiveConstraints:]
से बुलाया जाता है, जिसे तेज किया जा सकता है। ,
void -[UIView engine:willBreakConstraint:dueToMutuallyExclusiveConstraints:] {
if ([self _isUnsatisfiableConstraintsLoggingSuspended]) {
[self _recordConstraintBrokenWhileUnsatisfiableConstraintsLoggingSuspended:$arg4]; // add constraint to some pool
}
else {
if (__UIConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints) {
// print something in os_log
}
else {
_UIViewAlertForUnsatisfiableConstraints($arg4, $arg5);
}
}
}
अगर मैं this article से सही ढंग से समझ, __UIConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints
हमेशा iOS पर कोई वापस आ जाएगी तो तुम सब करने की जरूरत है निजी bool संपत्ति _isUnsatisfiableConstraintsLoggingSuspended
कहा जाता है की जाँच करें और मूल विधि तो कॉल करने के लिए है: यह विधि लगभग इस सामग्री है।
इस परिणाम कोड उदाहरण है:
#import <objc/runtime.h>
void SwizzleInstanceMethod(Class classToSwizzle, SEL origSEL, Class myClass, SEL newSEL) {
Method methodToSwizzle = class_getInstanceMethod(classToSwizzle, origSEL);
Method myMethod = class_getInstanceMethod(myClass, newSEL);
class_replaceMethod(classToSwizzle, newSEL, method_getImplementation(methodToSwizzle), method_getTypeEncoding(methodToSwizzle));
class_replaceMethod(classToSwizzle, origSEL, method_getImplementation(myMethod), method_getTypeEncoding(myMethod));
}
@interface InterceptUnsatisfiableConstraints : NSObject
@end
@implementation InterceptUnsatisfiableConstraints
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SEL willBreakConstantSel = NSSelectorFromString(@"engine:willBreakConstraint:dueToMutuallyExclusiveConstraints:");
SwizzleInstanceMethod([UIView class], willBreakConstantSel, [self class], @selector(pr_engine:willBreakConstraint:dueToMutuallyExclusiveConstraints:));
});
}
- (void)pr_engine:(id)engine willBreakConstraint:(NSLayoutConstraint*)constraint dueToMutuallyExclusiveConstraints:(NSArray<NSLayoutConstraint*>*)layoutConstraints {
BOOL constrainsLoggingSuspended = [[self valueForKey:@"_isUnsatisfiableConstraintsLoggingSuspended"] boolValue];
if (!constrainsLoggingSuspended) {
NSLog(@"_UIViewAlertForUnsatisfiableConstraints would be called on next line, log this event");
}
[self pr_engine:engine willBreakConstraint:constraint dueToMutuallyExclusiveConstraints:layoutConstraints];
}
@end
यह आईओएस 8.2/9/10 (यह आईओएस 8.1 में काम नहीं करता है, तो सावधान रहना होगा) पर काम करता है, लेकिन मैं किसी भी गारंटी नहीं दे सकता। इसके अलावा, यह सिस्टम घटकों, जैसे कुंजीपटल/वीडियो प्लेयर/आदि में बाधा समस्याओं को पकड़ता है। यह कोड नाजुक है (यह किसी भी सिस्टम संस्करण अद्यतन, पैरामीटर परिवर्तन, आदि पर क्रैश हो सकता है) और मैं इसे उत्पादन में उपयोग करने की अनुशंसा नहीं करूंगा (अनुमान लगाएं कि यह स्वचालित समीक्षा प्रक्रिया भी पास नहीं करेगा)। आपके पास अंतिम शब्द है, लेकिन आपको चेतावनी दी गई है।
हालांकि मुझे लगता है कि आप उत्पादन से पहले ऑटोलायआउट में बग को ठीक करने के लिए आंतरिक/बाहरी परीक्षकों के निर्माण में इसका उपयोग कर सकते हैं।
नोटिस कि आप तेजी से उपयोग कर रहे हैं: आप इस कोड को अपने स्विफ्ट प्रोजेक्ट में ब्रिजिंग हेडर फ़ाइल के साथ जोड़ सकते हैं।
यह एक अच्छा सवाल है। जैसा कि मैं इसे समझता हूं, प्रतीकात्मक ब्रेकपॉइंट्स आपको एक विशिष्ट प्रतीक, विधि या चयनकर्ता को तोड़ने की अनुमति देता है।मैंने ग्लोबल सी फ़ंक्शन 'UIViewAlertForUnsatisfiableConstraints()' को बाहर करने का प्रयास किया है और यह देखने के लिए देख रहा हूं कि यह 'UIView' पर एक उदाहरण या क्लास विधि है लेकिन मुझे अभी तक कुछ भी नहीं मिला है। – JAL