2017-09-21 11 views
7

के लिए सुरक्षित क्षेत्र के बारे में आईओएस 11 लेआउट मार्गदर्शन, मेरा आवेदन पहले से ही ऐप स्टोर में है, कल मैंने अपने एक्सकोड संस्करण को 9 तक अपडेट किया है और आईफोन एक्स को छोड़कर ठीक काम करता है। यूआई गिर गयाआईफोन 11

1.Here मैं दो UIView (दोनों ऊंचाई तय कर रहे हैं) हैडर के रूप में नामित और टैब बार बनाया गया है और मैं अपने NavigationBar पूरे एप्लिकेशन को छुपाया है।

self.addHeaderTab(currentViewController: self, content:"நிகழ்ச்சி நிரல்" , isMenu: true) 

कि टैब बार की तरह:

2.Added विस्तार UIViewController को हैडर और टैब बार

func addHeaderTab(currentViewController:UIViewController,content:String, isMenu:Bool){ 
     let noView = TopHeaderView() 
     noView.tag = 12345 
     noView.isMenu = isMenu 
     noView.translatesAutoresizingMaskIntoConstraints = false 
     currentViewController.view .addSubview(noView) 
     if isMenu{ 
      noView.menuBtn .setImage(UIImage(named: "Small"), for: .normal) 
      noView.logoImg.isHidden = false 

     }else{ 
      noView.menuBtn .setImage(UIImage(named: "arrow_small"), for: .normal) 
      noView.logoImg.isHidden = true 
     } 
     noView.titleLbl.text = content 
     noView.delegate = (currentViewController as! menuOpen) 

     NSLayoutConstraint(item: noView, attribute: .leading, relatedBy: .equal, toItem: currentViewController.view, attribute: .leading, multiplier: 1.0, constant: 0.0).isActive = true 

     NSLayoutConstraint(item: noView, attribute: .trailing, relatedBy: .equal, toItem: currentViewController.view, attribute: .trailing, multiplier: 1.0, constant: 0.0).isActive = true 

     NSLayoutConstraint(item: noView, attribute: .top, relatedBy: .equal, toItem: currentViewController.view, attribute: .top, multiplier: 1.0, constant: 0.0).isActive = true 

     NSLayoutConstraint(item: noView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64).isActive = true 

    } 

बनाने और इस हर ViewController नीचे की तरह फोन करने के लिए मैंने भी किया है लेकिन सभी डिवाइस काम कर रहे हैं आईफोन एक्स

Image

मैं के बारे में https://developer.apple.com/ios/human-interface-guidelines/overview/iphone-x/

का अध्ययन किया लेकिन उनके दस्तावेज के साथ स्पष्ट नहीं कर रहा हूँ है:

मेरे स्क्रीन शॉट देखें।

सहायता की सराहना की जाएगी, अग्रिम धन्यवाद।

उत्तर

13

आईओएस 11 (और आईफोनएक्स की उपस्थिति) के साथ ऐप्पल ने सुरक्षित क्षेत्र लेआउट गाइड को आईफोनएक्स में अपने विचारों को अनुकूलित करने के लिए पेश किया।

सुरक्षित क्षेत्र स्क्रीन का वह क्षेत्र है जो पायदान या घर सूचक द्वारा ओवरलैप नहीं किया जाता है।

enter image description here

मुद्दा क्या आप iOS11 के लिए अपने noView के प्रमुख बाधा बदलना होगा सामना कर रहे हैं से बचने के लिए:

if #available(iOS 11, *) { 
    let guide = view.safeAreaLayoutGuide 
    NSLayoutConstraint.activate([ 
     noView.topAnchor.constraint(equalTo: guide.topAnchor) 
    ]) 
} else { 
    NSLayoutConstraint.activate([ 
     noView.topAnchor.constraint(equalTo: currentViewController.topLayoutGuide.bottomAnchor) 
    ]) 
} 
NSLayoutConstraint.activate([ 
    noView.leadingAnchor.constraint(equalTo: currentViewController.view.leadingAnchor), 
    noView.trailingAnchor.constraint(equalTo: currentViewController.view.trailingAnchor), 
    noView.heightAnchor.constraint(equalToConstant: 65) 
]) 

दुर्भाग्य से यही सब कुछ नहीं है। क्योंकि अब आपके noView आईफोन एक्स पर नीचे चला गया है, लेकिन स्टेटस बार में अब लाल पृष्ठभूमि नहीं है।

enter image description hereenter image description here

आप चीजों को एक UINavigationController का उपयोग करके बहुत आसान बना सकता है (एक लाल नेविगेशन पट्टी के साथ):: आप स्थिति पट्टी के पीछे एक लाल रंग की पृष्ठभूमि रंग जोड़ने है

enter image description hereenter image description here

इस दृष्टिकोण के साथ आपको कोई बाधा निर्धारित करने की आवश्यकता नहीं है! सिस्टम स्वचालित रूप से आपके लिए सभी समायोजन करता है।

+0

आप बहुत मददगार थे, धन्यवाद बहुत ... क्या नेविगेशन बार में कस्टम UIView लोड करने का कोई तरीका है? यदि ऐसा है, तो कोई समस्या नहीं है, क्या मैं सही हूँ? क्या आपको इस – karthikeyan

+0

पर कोई विचार है, आप अपने व्यू कंट्रोलर के 'UINavigationItem' (जब आपका व्यू कंट्रोलर नेविगेशन नियंत्रक में एम्बेड किया गया है) का उपयोग करके नेविगेशन बार को कस्टमाइज़ कर सकते हैं। आप बटन आइटम और शीर्षक दृश्य जोड़ सकते हैं (जो कि कोई भी 'UIView' हो सकता है)। इन दस्तावेज़ों पर एक नज़र डालें: https://developer.apple.com/documentation/uikit/uinavigationitem – joern

+0

मैंने शीर्षक दृश्य में xib और सबव्यू लोड करने का प्रयास किया लेकिन – karthikeyan

2

ऊपर और नीचे मार्जिन के लिए ऑब्जेक्टिव-सी जब iPhone एक्स

if (@available(iOS 11, *)) { 

    NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:self.childView 
                      attribute:NSLayoutAttributeBottom 
                      relatedBy:NSLayoutRelationEqual 
                      toItem:self.parentView.safeAreaLayoutGuide 
                      attribute:NSLayoutAttributeBottom 
                     multiplier:1.0 
                      constant:0]; 


    NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.childView 
                    attribute:NSLayoutAttributeTop 
                    relatedBy:NSLayoutRelationEqual 
                     toItem:self.parentView.safeAreaLayoutGuide 
                    attribute:NSLayoutAttributeTop 
                    multiplier:1.0 
                    constant:0]; 


} else { 

    NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:self.childView 
                     attribute:NSLayoutAttributeBottom 
                     relatedBy:NSLayoutRelationEqual 
                     toItem:self.parentView 
                     attribute:NSLayoutAttributeBottom 
                    multiplier:1.0 
                     constant:0]; 


    NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.childView 
                    attribute:NSLayoutAttributeTop 
                    relatedBy:NSLayoutRelationEqual 
                     toItem:self.parentView 
                    attribute:NSLayoutAttributeTop 
                    multiplier:1.0 
                    constant:0]; 

} 
0

आप एक UINavigationController का उपयोग नहीं करना चाहते हैं, लेकिन क्या आप इस तरह से कर सकते हैं एक नेविगेशन पट्टी करना चाहते हैं, तो (पर में एक UIImageView) का उपयोग:

https://medium.com/@kahseng.lee123/creating-custom-navigation-bar-tab-bar-for-iphone-x-f03b1e1827d3

या आप एक दृश्य बना सकते हैं और superview के शीर्ष और नेविगेशन पट्टी के शीर्ष करने के लिए अपने नीचे contraint करने के लिए अपने शीर्ष बाधा सेट कर सकते हैं। इसे लाल बनाने के लिए मत भूलना। :-)