2017-07-04 16 views
7

मुझे आईओएस में UINavigationBar बग मिला। self.navigationItem.rightBarButtonItems = @[fixSpaceItem, item] के साथ दृश्य में सेटअप नेविगेशन आइटम बटन। और जेस्चर पॉप बैक का उपयोग करें, लेकिन जब मैं पॉप बैक शुरू करता हूं, तो मैं वास्तव में वापस नहीं आ जाता, मैं अपनी उंगली छोड़ देता हूं और व्यू कंट्रोलर पॉप को वापस रद्द कर देता हूं, फिर दाएं नेविगेशन बटन आइटम गायब हो जाते हैं। बाएं आइटम बटन में एक ही समस्या है। इस बग को पुन: उत्पन्न करने के लिए, आपको [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] जैसे fixSpaceItem जोड़ना होगा। और असली डिवाइस लेकिन सिम्युलेटर बग को पुन: पेश नहीं कर सकता है।आईओएस 11 नेविगेशन BarButtonItems बग कैसे संभालें?

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.navigationController.interactivePopGestureRecognizer.enabled = YES; 
    self.navigationController.interactivePopGestureRecognizer.delegate = self; 

    self.navigationItem.rightBarButtonItems = @[[self negativeSpacerWithWidth:5],[self rightButton]]; 
    self.navigationItem.leftBarButtonItems = @[[self negativeSpacerWithWidth:5], [self leftButton]]; 

} 

- (UIBarButtonItem *)leftButton { 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)]; 
    [button setImage:[UIImage imageNamed:@"icon_app_back_normal"] forState:UIControlStateNormal]; 
    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; 
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button]; 
    return item; 
} 

- (UIBarButtonItem *)rightButton { 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)]; 
    [button setImage:[UIImage imageNamed:@"setting"] forState:UIControlStateNormal]; 
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button]; 
    return item; 
} 

- (UIBarButtonItem *)negativeSpacerWithWidth:(CGFloat)width { 
    UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 
    [spacer setWidth:width]; 
    return spacer; 
} 
+0

मैं एक ही दिखाई दे रही है भी तय अंतरिक्ष के बिना। मेरे मामले में, एनएवी बार उस व्यू कंट्रोलर के नेविगेशन आइटम को अपडेट करता है जिसे आप पॉप-अप कर रहे हैं, लेकिन जब आप पॉप मिड-इशारा रद्द करते हैं तो वर्तमान दृश्य नियंत्रक नेविगेशन आइटम पर कभी भी वापस नहीं आते। उम्मीद है कि अगले बीटा में इसे मंजूरी दे दी जाएगी। –

उत्तर

1

यह एक बग है जब आप FixedSpace BarButtonItemBarButtonItem array में जोड़ने के लिए लगता है: यहाँ मेरी मुख्य कोड है। यदि आप नेविगेशन आइटम पर ऑफ़सेट सेट करना चाहते हैं, तो उसे किसी अन्य तरीके का उपयोग करना पड़ सकता है, जैसे बटन के imageEdgeInsets को बदलना।

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    // Do not set Fixed Space type button item. 
    self.navigationItem.leftBarButtonItem = [self leftButton]; 
    self.navigationItem.rightBarButtonItem = [self rightButton]; 

    // It work too 
    //self.navigationItem.leftBarButtonItems = @[[self leftButton], [self leftButton]]; 
    //self.navigationItem.rightBarButtonItems = @[[self rightButton], [self rightButton]]; 


    self.navigationController.interactivePopGestureRecognizer.enabled = YES; 
    self.navigationController.interactivePopGestureRecognizer.delegate = self; 
} 

- (UIBarButtonItem *)leftButton 
{ 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)]; 
    //... 

    // to add offset you want 
    button.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15); 

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button]; 
    return item; 
} 

- (UIBarButtonItem *)rightButton 
{ 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)]; 
    //... 

    // to add offset you want 
    button.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, -15); 

    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button]; 
    return item; 
} 
0

मैंने नेविगेशन आइटम के भीतर इसे फिट करने के लिए छवि का आकार बदलने का प्रयास किया और यह काम किया। यद्यपि आपको वास्तव में अपनी छवियों का आकार बदलने की आवश्यकता नहीं है, फिर भी आप रनटाइम पर छवि का आकार बदलने के लिए दिए गए फ़ंक्शन का उपयोग कर सकते हैं।

UIImage *imgCart = [self imageWithImage:[UIImage imageNamed:@"ic_cart"] scaledToSize:CGSizeMake(35, 35)] ; 
    UIButton *btnCart = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; 
    [btnCart addTarget:self action:@selector(btnCartClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    [btnCart setBackgroundImage:imgCart forState:UIControlStateNormal]; 
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnCart]; 



-(UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { 
    //UIGraphicsBeginImageContext(newSize); 
    // In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution). 
    // Pass 1.0 to force exact pixel size. 
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0); 
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; 
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return newImage; 
} 
+0

स्क्रिप्ट ब्लॉक में ओब्जे सी कोड को शामिल न करें – NSNoob

0
let hamButtonWidthConstraint = hamButton.widthAnchor.constraint(equalToConstant: 40) 

let hamButtonHeightConstraint = hamButton.heightAnchor.constraint(equalToConstant: 40) 

hamButtonWidthConstraint.isActive = true 

hamButtonHeightConstraint.isActive = true 
संबंधित मुद्दे