In an iPhone app I get the following phenomenon, when handling (rotating) a UITableView.
(The problem may have nothing to do with UITableView itself, but….)
When I rotate: things appear OK for the vertical view, but for the horizontal view I get a white rectangle in the upper left corner. How this can be? I expect a View not being where it ought to be or not being set up as it ought to. But if this is the case how can I identify this view? I did not find anything suspicious in my code. And apart from this rectangle coming from nowhere, everything works fine.
I found the problem. It was due to a difference in the resources. Under Interface Builder I found that the resources I used for the vertical and horizontal views were not set up the same way. After changing that, the problem disappeared.
Related
So I have a UITextView, and in viewDidLoad I rotate its layer so it appears to be slanted back into the screen (sort of like the Star Wars opening crawl).
The problem is that scrolling is all messed up. Dragging up will scroll for a bit, then jump backward or similar; on the simulator it will even crash sometimes with an error about a coordinate containing NaN.
Similarly, when I try to automatically scroll the UITextView via [UIView animateWithDuration:...] I also get unexpected skips, jerks, etc.
I assume this has something to do with the fact that I've manipulated the layer, but the touch events as well as the animations are registered on the view... Or something like that?
Anyway, I'm pretty stumped.
Are you using constraints to position the text view? There seem to be issues with using transformations and constraints together. A common workaround seems to be to wrap the offending item in another view. The big issues are on iOS7, but some applies to iOS8 as well. This link discusses the issues which may be your issue:
How do I adjust the anchor point of a CALayer, when Auto Layout is being used?
For some reason I cannot get all switches to display properly on a screen. Some of them appear to be overwritten on the left edge but from what I can determine all of the switches and text views are correct. Any suggestions are welcome
So first, to make sure that this is the problem: while your app is running, click on the two rectangles overlapping on the right of the Debug Area to "Debug View Hierarchy"
When you have that, rotate your views to make sure that in every row you don't have your text views overlapping your switches. That's what it looks like what's happening, but you can use this tool to confirm so.
If so, and you are using auto layout, make sure you are setting your constraints correctly. If not, then make sure you are setting the width properly. To prove it's an autolayout issue, you could temporarily hard code a length to every text view to see if the issue is still there. If that fixes it, than auto-layout is just making your textviews wider than they should be.
Good luck!
I've updated my old pre-AutoLayout view to use AutoLayout. All warnings and errors are gone. I can successfully switch the simulated size to any iPhone and it will work.
However, once I run on actual hardware, the UIImageView that I've set as a background image seems to be hiding all the content (either that or the other content is being pushed off). I've verified that the UIImageView is closest to the root, so it should have the lowest z-index position. When I delete the UIImageView, all the content appears as expected.
If this helps: I've pinned the leading, trailing, top and bottom values of the UIImageView to the superview sides and the respective navbar/toolbar edges.
I've since confirmed it's merely covering the other content by setting a transparency value. So for whatever reason, it's getting pulled to the front. If anyone has intimate knowledge of AutoLayout and has some sane reason as to why that's happening, I'd love to hear it, otherwise, I'll chalk it up to just quirkiness.
I believe the underlying XML of the view had issues.
Solution Summary:
Removed setTranslatesAutoresizingMaskIntoConstraints:NO code.
Re-dragged background image to original position in hierarchy.
Details:
After digging around with the commands that Rob showed me, I was able to confirm that there were a lot of ambiguous layout errors at runtime only. I couldn't see anything inherently wrong with the constraints in Interface Builder, but after redoing the constraints several times and still having no luck, I removed the following from my view controller code:
setTranslatesAutoresizingMaskIntoConstraints:NO
That immediately removed the ambiguity errors.
Why did I put that in there? I have no real good reason other than having read some blogs suggesting to do so. Lesson learned, don't blindly do things.
However, this actually still did not fix the original problem. I reran the program and the background image was still jumping to the front of all sibling subviews even though there were no longer any ambiguity errors.
I was able to send it manually to the back by executing
sendSubviewToBack: against lldb.
and the view looked as intended. With no ambiguity errors remaining I decided to just drag the background uiimageview to a new position in the view hierarchy, then I executed the code. Then I stopped and dragged the uiimageview back to its original position, and executed again. And voila, it was in the proper position. I can only imagine the underlying XML had problems.
I'm trying to use Auto Layout for a custom Table View Cell in my app.
I can't seem to get the constraints quite right.
I layed the labels out in the custom Table View Cell, but the labels are still getting cut off. Any ideas?
Thanks! Will post anything else needed. Tried to show needed info in picture below:
Debugging in Xcode. Somehow what shows in Simulator looks different than in Xcode debug.
Here's the width of my TableView shown:
UPDATE:
The problem here was related to what user matt said in the accepted answer, but I wanted to make the Q&A a bit clearer now that I have it figured out for anyone else that comes across this.
In his initial comment, he mentioned the Xcode View debugging, which was great and I was able to dig into a little bit more. Its called the Assistant Editor: Device Preview, where you are able to see the layout and layers of what is onscreen to see if maybe you have labels overlapping or going offscreen based on the device it is running on. If you want to check multiple device sized, just hit the plus icon in the lower left hand corner of this picture.
This helped me find overlapping layers and sizing issues with the TableView. I was able to see how it looked on each device size.
What also helps here sometimes to use the Pin menu. Sometimes the labels can run off screen because it doesn't know where the constraints of the cell are based on the device size. So your label can run offscreen if the label is based off of a landscape layout but the device is an iPhone 5 and is in Portrait for example. This is the Pin menu:
Hope that makes sense and gives some more color to the problem. Let me know if you have any questions at all, thanks for the help everyone!
The problem is that you are using auto layout but you have not done anything about sizing the table view. The table view here is not your view controller's view; it is a subview. Your view controller's view is automatically sized to the size of the device / window, but its subviews are not automatically resized. So you are ending up with the table view much too wide for the device; the whole table is sticking off into space on the right side.
Use a trailing space from the right side of your labels to the edge of their superview, and set it to greater than instead of equals with a value of ~ 5
Review the constraints of your tableview with the View. Draw cell border, label border and tableview border with different colors to know which elements do not display correctly.
Ex:
#import <QuartzCore/QuartzCore.h>
...
cell.layer.border.width = 1;
cell.layer.border.color = [UIColor blackColor].CGColor;
The thing that worked for me to solve views being clipped was to uncheck "Constrain to margins" in Auto Layout.
I have subclassed and am using UIPopoverBackgroundView in order to make custom appearances for my UIPopoverControllers. Everything seems to work great so far, the popover draws well and looks the way I expect it.
The issue is that, when my popover is left open for a period of time with no activity, the border will often suddenly be drawn wrong. This specifically seems to only happen when the popover contains a scrollview/tableview which is larger than the popover (i.e. it is scrollable). It also doesn't happen every time, but if it does happen, it occurs in less than one minute of inactivity. If I take a screenshot, the issue is not visible (despite it clearly being seen on screen) so I can't provide any images of the issue unfortunately.
Does anyone know of any reason why the border would be drawn incorrectly after several seconds of inactivity and how to fix the issue? I can provide snippets of code if necessary, though I'm fairly certain everything is right (and equivalent to the many examples I've seen online). I also do not resize the popover at any time during the inactivity (I do resize when initially displayed to fit the content up to a maximum size).
Since I can't take a screenshot to demonstrate the issue, the best I can do is describe it. It appears as if the border in certain areas is drawn at the wrong size (as in, part of the right edge is being drawn in the middle of the popover; NOT that the border itself is too wide, but rather that the area the border should be bordering is wrong). The area along the actual edge is still there, but is lacking it's layer effects (I have the backgroundView using a border and rounded corner layer effect to give it a nice rounded white edge, emulating the same appearance as the default background view, just a different color). Removing the layer effects does not prevent the issue though. Sometimes it's only a part of the right edge which is drawn incorrectly, sometimes part of the bottom edge is also affected. I can't seem to find any correlation as to when or how this happens (though it is frequent), nor to which edge is affected (though I've never seen it affect the top or left edge).
Does it only happen in the simulator or also on a real device?
This specifically seems to only happen when the popover contains a scrollview/tableview which is larger than the popover (i.e. it is scrollable)
Do you resize the scrollview / tableview in this case? Try adding a UIView inside your UIPopView that would be the container.