Manually setting a UITextView frame always fails at one photo and then affects the rest
<p>I'm working on a Swift 2.0 app that contains an <a href="https://github.com/MailOnline/ImageViewer" rel="nofollow noreferrer">imageViewer</a>, the footerView of each image will change to the photo's description text. For example, if I click on Manhattan Bridge and allow the footerView to be shown fully whenever I arrive at the 9th image the UITextView collapses to the smallest height. At this point a UITextView that should have a height of 105 pixels now has a height of 75 pixels.</p>

<p>Scrolling forwards and returning fixes the problem. Scrolling backwards causes problems on the previous images that were showing perfectly. Pressing the UITextView to make it compact and pressing it again to bring it to its full frame will fix the problem.</p>

<pre><code>        galleryViewController.landedPageAtIndexCompletion = { index in
            if self.galleryViewController.footerView?.frame.height != 75.0 &amp;&amp; self.galleryViewController.footerView?.frame.height != 100.0{
                print("LANDED AT INDEX: \(index)")
                let footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height)
                self.footerView.frame = footerFrame
                let description = self.lastTappedLocationDataPassed[index]["description"] as! String
                headerView.currentIndex = index
                self.footerView.year = self.lastTappedLocationDataPassed[index]["date"] as! String
                self.footerView.summary = description

                let contentSize: CGFloat = (self.footerView.yearLabel?.contentSize.height)! + 6
                if contentSize &gt; 600{
                    if UIDevice.currentDevice().orientation.isLandscape{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.height, height: 600.0)
                    }else if UIDevice.currentDevice().orientation.isPortrait{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 600.0)
                    }else if UIDevice.currentDevice().orientation.isFlat{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 600.0)
                    }
                }else if contentSize &lt; 100.0{
                    if UIDevice.currentDevice().orientation.isLandscape{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.height, height: 105.0)
                    }else if UIDevice.currentDevice().orientation.isPortrait{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 105.0)
                    }else if UIDevice.currentDevice().orientation.isFlat{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 105.0)
//                        BREAKPOINT
                    }
                }else{
                    if UIDevice.currentDevice().orientation.isLandscape{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.height, height: contentSize)
                    }else if UIDevice.currentDevice().orientation.isPortrait{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: contentSize)
                    }else if UIDevice.currentDevice().orientation.isFlat{
                        self.footerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: contentSize)
//                        BREAKPOINT
                    }
                }
                self.galleryViewController.footerView = self.footerView
                self.galleryViewController.footerView?.layoutIfNeeded()
            }else{
                var footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: UIScreen.mainScreen().bounds.height)
                if UIDevice.currentDevice().orientation.isLandscape{
                    footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.height, height: 100.0)
                }else if UIDevice.currentDevice().orientation.isPortrait{
                    footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 100.0)
                }else if UIDevice.currentDevice().orientation.isFlat{
                    footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 100.0)
                }
                self.galleryViewController.footerView?.frame = footerFrame
                print("LANDED AT INDEX: \(index)")

                headerView.currentIndex = index
                let description = self.lastTappedLocationDataPassed[index]["description"] as! String
                var substring = ""
                if description.characters.count &gt; 29{
                    substring = description.substringToIndex(description.startIndex.advancedBy(30))
                }else{
                    substring = description
                }
                self.footerView.year = self.lastTappedLocationDataPassed[index]["date"] as! String
                self.footerView.summary = substring
            }
//            BREAKPOINT
        }

        self.presentImageGallery(galleryViewController)
    }
</code></pre>

<p>I've put breakpoints in the code, each time right before the UITextView is altered the frame shows exactly as it should.</p>

<pre><code>(lldb) po self.footerView.frame
▿ CGRect
  ▿ origin : CGPoint
    - x : 0.0
    - y : 0.0 { ... }
  ▿ size : CGSize
    - width : 320.0
    - height : 105.0

(lldb) po self.footerView.frame
▿ CGRect
  ▿ origin : CGPoint
    - x : 0.0
    - y : 0.0 { ... }
  ▿ size : CGSize
    - width : 320.0
    - height : 105.0

(lldb) po self.galleryViewController
&lt;oldNYC_iOS.GalleryViewController: 0x15e847200&gt;

(lldb) po self.galleryViewController.footerView?.frame
▿ Optional&lt;CGRect&gt;
  ▿ Some : CGRect
    ▿ origin : CGPoint
      - x : 0.0
      - y : 0.0 { ... }
    ▿ size : CGSize
      - width : 320.0
      - height : 105.0
</code></pre>

<p>This is what is displayed, it has a height of 75:
<a href="https://i.stack.imgur.com/i3yon.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i3yon.png" alt="incorrectSize"></a></p>

<p>This is what should be displayed:
<a href="https://i.stack.imgur.com/i1tVT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i1tVT.png" alt="correctSize"></a></p>

<p>This happens randomly and moving forward or backwards possibly fixes the problem.</p>

<p>Any thoughts?</p>

<p>EDIT:
Contains FooterView constraints code:
This is the code used in that original ImageViewer file...</p>

<pre><code>    func setupTextView() {
    yearLabel = UITextView(frame: CGRectZero, textContainer: nil)
    yearLabel?.translatesAutoresizingMaskIntoConstraints = false
    yearLabel?.editable = false
    yearLabel?.scrollEnabled = true
    yearLabel?.dataDetectorTypes = .None
    yearLabel?.backgroundColor = UIColor.clearColor()
    yearLabel?.textContainerInset = UIEdgeInsetsMake(2.0, 2.0, 0.0, 2.0)
    self.addSubview(yearLabel!)
    let topConstraint: NSLayoutConstraint = NSLayoutConstraint(item: yearLabel!, attribute: .Top, relatedBy: .Equal, toItem: yearLabel!, attribute: .Top, multiplier: 1.0, constant: 0.0)
    let bottomConstraint: NSLayoutConstraint = NSLayoutConstraint(item: yearLabel!, attribute: .Bottom, relatedBy: .Equal, toItem: yearLabel!, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
    let widthConstraint: NSLayoutConstraint = NSLayoutConstraint(item: yearLabel!, attribute: .Width, relatedBy: .Equal, toItem: yearLabel!, attribute: .Width, multiplier: 1.0, constant: 0.0)
    let horizontalPositionConstraint: NSLayoutConstraint = NSLayoutConstraint(item: yearLabel!, attribute: .CenterX, relatedBy: .Equal, toItem: yearLabel!, attribute: .CenterX, multiplier: 1.0, constant: 0.0)
    yearLabel!.addConstraints([topConstraint, bottomConstraint, widthConstraint, horizontalPositionConstraint])
}

override func layoutSubviews() {
    super.layoutSubviews()
    yearLabel!.frame = self.bounds
    yearLabel!.setContentOffset(CGPointZero, animated: false)
    yearLabel!.contentOffset.x = 0.0
    yearLabel!.contentOffset.y = 0.0
    if UIDevice.currentDevice().orientation.isLandscape{
        yearLabel!.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.height, height: (yearLabel?.bounds.size.height)!)
    }else{
        yearLabel!.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: (yearLabel?.bounds.size.height)!)
    }
}
</code></pre>

<p>EDIT 2:
When I set each open footerView with the same height there are no problems, as soon as I begin to add any type of extra if clause problems occur.</p>

<pre><code>        if description.characters.count &lt; 500{
            if UIDevice.currentDevice().orientation.isLandscape{
                footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.height, height: 200.0)
            }else if UIDevice.currentDevice().orientation.isPortrait{
                footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 200.0)
            }else if UIDevice.currentDevice().orientation.isFlat{
                footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 200.0)
            }
        }else{
            if UIDevice.currentDevice().orientation.isLandscape{
                footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.height, height: 100.0)
            }else if UIDevice.currentDevice().orientation.isPortrait{
                footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 100.0)
            }else if UIDevice.currentDevice().orientation.isFlat{
                footerFrame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 100.0)
            }
        }
</code></pre>

<p>EDIT3:
I found that this error shows occassionally.</p>

<pre><code>2016-04-26 19:56:22.123 oldNYC-iOS[2835:1314856] -[&lt;_UITileLayer: 0x15a2590b0&gt; display]: Ignoring bogus layer size (2951479051793528258560.000000, 2361183241434822606848.000000), contentsScale 2.000000, backing store size (5902958103587056517120.000000, 4722366482869645213696.000000)
</code></pre>