2014-09-10 12 views
7

Wie bekomme ich eine Scroll-Ansicht, um mit Auto-Layout zu arbeiten, um seine Inhaltsgröße zu berechnen?UIScrollView bricht bei der Verwendung von automatischem Layout für Größe auf iOS 8/Xcode 6 GM Seed

Es scheint, dass Xcode 6 eine Einschränkung "UIView Encapsulated Layout Height" immer dann erstellt, wenn eine Scroll-Ansicht (mit Autolayout) vorhanden ist. Diese Einschränkung setzt die Höhe zwangsweise auf die Rahmenhöhe (wodurch die Bildlauffunktionalität einer Bildlaufansicht wiedergegeben wird) nutzlos).

Layout broken - iPhone 5s Simulator in Xcode 6 GM Seed

Fehler:

2014-09-09 21:06:01.059 ScrollViewLayoutBreaking[24488:88731] Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7f9a19ebd150 V:[UIView:0x7f9a19ea7f90(530)]>", 
    "<NSLayoutConstraint:0x7f9a19ec1370 V:[UIView:0x7f9a19ebd5e0(110)]>", 
    "<NSLayoutConstraint:0x7f9a19ea9ee0 V:[_UILayoutGuide:0x7f9a19ec18d0]-(0)-[UIView:0x7f9a19ea7f90]>", 
    "<NSLayoutConstraint:0x7f9a19ec1fa0 V:[UIView:0x7f9a19ea7f90]-(0)-[UIView:0x7f9a19ebd5e0]>", 
    "<NSLayoutConstraint:0x7f9a19e8d270 V:[UIView:0x7f9a19ebd5e0]-(5)-[_UILayoutGuide:0x7f9a19ec2260]>", 
    "<_UILayoutSupportConstraint:0x7f9a19ea0ac0 V:[_UILayoutGuide:0x7f9a19ec18d0(0)]>", 
    "<_UILayoutSupportConstraint:0x7f9a19ea7380 V:|-(0)-[_UILayoutGuide:0x7f9a19ec18d0] (Names: '|':UIScrollView:0x7f9a19ea76a0)>", 
    "<_UILayoutSupportConstraint:0x7f9a19e21d00 V:[_UILayoutGuide:0x7f9a19ec2260(0)]>", 
    "<_UILayoutSupportConstraint:0x7f9a19e8a930 _UILayoutGuide:0x7f9a19ec2260.bottom == UIScrollView:0x7f9a19ea76a0.bottom>", 
    "<NSLayoutConstraint:0x7f9a1c003f50 'UIView-Encapsulated-Layout-Height' V:[UIScrollView:0x7f9a19ea76a0(504)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f9a19ebd150 V:[UIView:0x7f9a19ea7f90(530)]> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

Edit: Alle Ansichten in dieser Scroll-Ansicht sind autolayouted und bereits gemerkt sowohl für die Scroll-Ansicht oben und unten, sowie beiden Seiten. Ich bin mir bewusst, dass es nicht gelingt, eine Inhaltsgröße zu erstellen, wenn es nicht auf allen vier Seiten gebunden wird. Das automatische Layout und das Scrollen sind in iOS 7/XCode 5 korrekt, aber der exakt gleiche Code und Storyboard-Break in iOS 8/XCode 6.

+0

Neu definierte Frage, um es kürzer und klarer zu machen. Derzeit mit Xcode 6 GM Seed. – Uzaak

+1

Noch keine Lösung? – jamespick

+0

Das Beste, was ich mir vorstellen konnte, war eine Tabellenansicht mit einer einzelnen selbsteinstellenden Zelle, die als Scroll-Ansicht, als Separator-Stil, dient. Aber das ist schrecklich genug für mich, um es als absolut letzten Ausweg zu benutzen. – Uzaak

Antwort

0

Dargestellt würde ich die Frage beantworten, da sie Antworten bis zu diesem Tag empfängt.

Der Code wird automatisch automatisch eingelesen. Wie in der Frage erwähnt, erzeugte der gleiche Code eine perfekte, keine Warnung/Fehler Scroll-Ansicht mit Xcode 5 und iOS 7, und würde eine Layouteinschränkung brechen, die ich nicht manuell in Xcode 6 GM Seed und iOS 8 erstellt hatte.

Es scheint so, als ob es sich um einen Xcode 6 GM Seed Fehler handelte, der gleiche Code funktionierte nahtlos in zukünftigen Updates von Xcode 6 nach der ersten Veröffentlichung, ohne irgendwelche Einschränkungen zu haben.

0

Durch Ihren Screenshot vermute ich, dass Sie benutzerdefinierte Ansichten in einem Scrollview verwenden ...

Ihre Inhaltsansichten sind: STH, Foo, Bar, Baz, qux, Blah, Woot, Lorem, Ipsum, Dolor

In Code, den Sie den Inhalt Größe automatisch mit automatischen Layout, indem Sie alle Ihre festlegen Inhaltsansichten, die miteinander in Beziehung stehen, mit Ausnahme der oberen und unteren Ansicht ... diese müssen sich auf die Kanten der Bildlaufansicht beziehen. Hier ein Beispiel:

-(void)example{ 

UIView *parentView; //Can be the Scroll View or the Scroll View superview, it's better for the ScrollView to be the Owner of the restrictions 
UIView *previousView; 
UIScrollView *scrollView; 

NSArray * arrayOfContentViews = @[STH,Foo,Bar,Baz,Qux,Blah,Woot,Lorem,Ipsum,Dolor]; 

for (UIView * currentView in arrayOfContentViews) { 

    //Important for Autolayout Restrictions 
    currentView.translateAutoresizingMask = NO; 
    [scrollview addSubview:currentView]; 

    if (previousView == nil) { 
     //For the Top, Left and Right Attribute Edges of the ScrollView 
     previousView = scrollView; 

     [parentView addConstraint:[NSLayoutConstraint constraintWithItem:currentView 
                   attribute:NSLayoutAttributeTop 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:previousView 
                   attribute:NSLayoutAttributeTop 
                   multiplier:1.0 
                   constant:0.0]]; 

     //10% of the scrollview Frame Size (not Content Size) 
     [parentView addConstraint:[NSLayoutConstraint constraintWithItem:currentView 
                   attribute:NSLayoutAttributeHeight 
                   relatedBy:NSLayoutRelationGreaterThanOrEqual 
                    toItem:previousView 
                   attribute:NSLayoutAttributeHeight 
                   multiplier:0.1 
                   constant:0.0]];    

    }else{ 

     [parentView addConstraint:[NSLayoutConstraint constraintWithItem:currentView 
                   attribute:NSLayoutAttributeTop 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:previousView 
                   attribute:NSLayoutAttributeBottom 
                   multiplier:1.0 
                   constant:0.0]]; 

     [parentView addConstraint:[NSLayoutConstraint constraintWithItem:currentView 
                   attribute:NSLayoutAttributeHeight 
                   relatedBy:NSLayoutRelationEqual 
                    toItem:previousView 
                   attribute:NSLayoutAttributeHeight 
                   multiplier:1.0 
                   constant:0.0]]; 
    } 

    [parentView addConstraint:[NSLayoutConstraint constraintWithItem:currentView 
                  attribute:NSLayoutAttributeLeft 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:previousView 
                  attribute:NSLayoutAttributeLeft 
                  multiplier:1.0 
                  constant:0.0]]; 

    [parentView addConstraint:[NSLayoutConstraint constraintWithItem:currentView 
                  attribute:NSLayoutAttributeRight 
                  relatedBy:NSLayoutRelationEqual 
                   toItem:previousView 
                  attribute:NSLayoutAttributeRight 
                  multiplier:1.0 
                  constant:0.0]]; 


    previousView = currentView; 

    } 

//Last View Dolor to the Bottom Edge of the scrollView 
[parentView addConstraint:[NSLayoutConstraint constraintWithItem:previousView 
                 attribute:NSLayoutAttributeBottom 
                 relatedBy:NSLayoutRelationEqual 
                  toItem:scrollView 
                 attribute:NSLayoutAttributeBottom 
                 multiplier:1.0 
                 constant:0.0]]; 
} 
0

Wenn Sie IB verwenden, wählen Sie den UIViewController aus, und wählen Sie im Menü AutoLayout die Option zum Entfernen aller Abhängigkeiten aus. Wählen Sie dann fehlende Einschränkungen hinzufügen. Dies löst Ihr Problem

0

Damit UIScrollView vertikal funktioniert, benötigt es die Kette der Teilansichten von oben nach unten.

Nun, wenn Sie mit dem oberen/unteren Rand seiner Subviews antrocknet Sie keine Ahnung Ansicht scrollen, wie sie es selbst machen sollte vertikal, wie es seine eigene Höhe berechnet basierend auf seinen Inhalt

was So sollten Sie tun, ist Mit scrollview können Sie unabhängig von den untergeordneten Elementen eine eigene Höhe festlegen.

Fügen Sie also Ihren Bildlauf in einer anderen Ansicht als Teilansicht mit der zugehörigen Abhängigkeit hinzu, und Sie können anschließend untergeordneten Elemente relativ zu Bildlauf hinzufügen.

Verwandte Themen