Artifacts after orientation change - ios

My app consists of 2 screen (main and settings) both are filled with scrollview completely. Each has one view controller and is supposed to support landscape and portrait orientations. I'm using Autosizing to achieve that and it works fairly well (all elements are where they should be, size is also correct) but I'm getting strange artifacts when the screen is rotated e.g. picker frame remains the same when the actual "drum" area inside is resized properly, text field is partially overlapped by background, landscape graph remains in place and is overlapped by portrait graph.
All are just basic elements without modifications, there are no images or anything special (graph is exception, I'm reloading it in didRotateFromInterfaceOrientation:). Any ideas why would that happen, why aren't the basic elements redrawn properly?

Figured it out myself in the end. Had to implement workaround as iOS apparently can't do it itself.
1) Artefacts after automatic view resize. Solution here was to hide the view before changing orientation, reload the graph and show it again after orientation was changed. Doesn't look perfect but much better than before.
2) Other problems were caused by the pickerview. Autoresize apparently doesn't work at all. The solution here was create UIView instead of the picker which resizes without problem and again recreate the pickerview every time the orientation changes.

Related

UICollectionView clipping on rotation, fixed as soon as you scroll

I’m using a UICollectionView to display three cells vertically, which each contain a UIView. It looks something like this:
If I rotate the device, it ends up looking like this:
I’m using AutoLayout to rotate the collection view, everything seems to be working properly, but when I rotate (this can be from portrait to landscape, or landscape to portrait), the collection view seems to clip its cells. If I turn on the view debugger at this point, it renders it perfectly there, like this:
As soon as I touch the collection view (i.e. scroll it slightly), the issue is fixed, and from then on it renders properly until I rotate again.
The issue occurs on both simulator and device, and when changing from any orientation to any other. It only clips until the collection view is touched, at which point it fixes itself.
I’ve tried lots of things already, replacing the YouTube views here with regular UIViews, manually calling scrollViewDidScroll: on the collection view after I rotate (and before), telling the collection view to reload its data, reload items, turning off clip or mask to bounds, invalidating the auto-resizing constraints, just about everything obvious that I can think of.
What’s puzzling me the most is the view debugger – everything there is perfect, it’s just when it renders out on-screen that it’s clipping. This issue occurs across the board, on all devices, phone and pad. There’s nothing in the view debugger hierarchy that looks like it’s overlapping them. Everything’s where it’s supposed to be, even if I break at the broken point and print frames, etc., it’s just clipping when it renders somehow.
Anyone have any suggestions?

Finer grained UIView rotation in a UIViewController

I have a UIViewController that overlays controls on a view presenting what the camera sees. I have a couple of scenarios I would like to allow.
For the iPad, I want to keep the controls on the right most edge of the device, by your right thumb, no matter what the device's rotation. The controls should rotate their content so that their top is always upwards (away from the ground). I don't want the camera view to rotate at all, because that would just be silly – its position & size should stay the same and its contents shouldn't rotate either.
For the iPhones, I want to keep the controls at the bottom of the device's screen, by to the home button, wherever the home button actually is. The controls should rotate their content so that up is always pointing upwards. Again, I don't want the camera view's frame or content to take part in any view rotation animation at all.
I'm using auto-layout.
I'm wondering if there is any way to describe some or all of this in a storyboard. In particular, it'd be great to be able to describe that some view positions need to autorotate (ie, the controls, on iPad), but that other views don't (the camera view).
A question from 2011 indicates this wasn't possible at the time, but perhaps things have moved on since then? If it's not directly supported, can you suggest an approach and are there some sensible places to be hooking in to autorotation to achieve this?
Ok, this isn't quite a complete answer, but I tried a few things which look promising.
First, you can create a separate set of constraints for portrait vs. landscape using the size specifiers: landscape is w Regular, h Any; portrait is w Any, h Regular (I think -- double-check these) This is accessible via the pop-up control in the bottom-center of the storyboard view. By installing different constraints for portrait and landscape, it should be possible to scale the width and height of your controls' container view so it appears to be in a constant position w.r.t. device orientation; in other words, the container doesn't actually counter-rotate -- it scales so it effectively looks like it has counter-rotated.
I got this close to working. It looks like it's doing the correct thing in the storyboard view, but when I actually run it, I get debug messages about conflicting constraints. Not sure how to fix this, but maybe play with the constraint priorities? That sometimes helps.
A second thing I (partially) tried was creating a custom container view class which counter-rotates itself to the correct position based on the device orientation (in the UIDevice class). You implement this by overriding layoutSubviews. For each orientation, you define a transform which puts it in the correct position, and set the view's transform property.
Another possible solution is to override updateConstraints in your view controller and add/remove constraints to position/scale your container to the correct place for each orientation.
For all of these, the idea is that you "force" the container to be in the correct place, but leave the subviews (the actual controls) alone. The controls should do the right thing if their constraints are independent of the specific orientation of the container view.
So, those are some ideas anyway... if they lead you to an actual solution, could you post it? I anticipate having a need for this myself.

MWPhotoBrowser - Images moving inside view

I am sure this is an easy question, but I am lost. I have MWPhotoBrowser and a bunch of photos loaded into the browser. Everything works beautifully, except if I click on an image in the browser and drag it around the screen it moves everywhere and repositions the image. Essentially I just want to stop if from dragging around all together.
Any recommendations ?
There were two issues causing this problem:
Autolayout was turned off. Since I wanted it to remain off I had to create a work around with #2.
The content appears to be sized to the View. In my case the view height was much larger than the available display area on the screen. To work around the issue I used another view sized to the viewable area and added the browser to that view rather than the super view.

IOS - How to get my text view object information to scroll on view?

I am using Mac OS X Lion 10.7.5 and XCode Version 4.6.1 (4H512),
I have looked at these answers on stackoverflow to try to figure out my question
-cannot make a text view scroll - xcode 4.3
-also posts that looked possible, when I searched on "scroll text in UITextView" within stackoverflow
Within Interface Builder I cannot figure out how to make information in a UiTextView object scroll within the iPhone simulator*. To resolve this challenge, I have made the most simple prototype project I can think of, just a view and one text view object on it, filling the text view object with a stream of text simply typed in via interface builder. For this most basic sample I'm using to sort out my problem, I have not done anything programatic. (Please note that I am aware of StoryBoards and have begun working through a book to learn to use them, but I would like to finish my first prototype app using what I’ve already learned and fully complete one project before I move onto my next project using StoryBoards.)
When I run this in the iPhone simulator, I see the sample information in my text view object come up. As I expected not all the information displays, due to my sizing the box a little too small on purpose. But I cannot flick or arrow down, or in any other way view the rest of the text information within the simulator. Nor do I see scrolling bars anywhere on the view. The information is just frozen in/on the view.
Inspector Settings
Identity Inspector
"Accessibility" Tested both with Enabled checked and not checked
Use Auto Layout is NOT checked
Attributes Inspector
Behavior Editable box not checked
Scroll View Area Checked ‘show horizontal scrollers, shows vertical scrollers and also scrolling enabled” The rest of the scrollers box are not checked
Bounces is checked
Zoom min and max are both 1
Touch all boxes checked- bounces zoom, delays content touches, cancellable content touches
View mode is ‘scale to fill”
Interaction ‘multiple touch’ is checked
Drawing checked opaque, clears graphics context, clip subviews, and autoresize subviews. Only ‘hidden’ is not checked
Size Inspector
I played around with the ‘scrolling insets’ boxes changing them from the default (I think it was 0 or 1), just to see if I noticed anything. I think maybe that I see some shadowy marker type lines in Interface builder in the area where I might expect a scroll bar when I make these changes, but no change in appearance within the simulator.
I cannot figure out why my actual iPhone device with everything up to date, is now not working as a test device, but I believe that is a separate challenge
how about wrapping you uitextfield in a uiscrollview. Make the scroll view the dimensions you currently are setting the uitextfield to, then allow your uitextfield to scale to the size of the text.
This is one of those questions that solved itself eventually. After twice creating the most basic app, with no programmatic bits just interface builder and a textView object with all the defaults the scrolling worked. The only reason I can think of that it might not have scrolled as expected the first time through may have had to do with placement of the textView object on the view. I wonder if it overlapped the bottom of the view and maybe that messes something up.
Just one of those situations where I had to keep plugging away, trying what seemed like the same thing repeatedly,set in the Inspectors, and suddenly, like magic, it worked. Except no magic involved.

UIViews display at wrong location in landscape mode

I am working on an diagramming application which displays boxes as subviews inside a larger view. The user can move the boxes around. I am persisting the positions of these boxes using core data into a sqlite database by holding the height, width, x and y (of the top-left corner). When I open up a diagram I am reading these values from the database and using them to set the frame of the subview within the main view.
In portrait mode this works fine and the boxes are repositioned at the correct points on the display. However, when I rotate into landscape, or start the application in landscape and open the diagram, the positions of the boxes are wrong.
I have traced through the code and can see that the correct values are coming back from the persistent store and being used to correctly set the frame. However, once the UIView for the subview is on screen it is positioned at a different location (clearly visible and confirmed by checking the values in the frame of the view).
Now the odd thing is that instead of being a fixed pixel offset, the x co-ordinate is always 8.5% larger than the value used to create the frame, and the y value is always 9.1% smaller.
Does anyone have any explanation as to why this might be and how I might solve the problem?
If it provides any clues, the main view is inside a UIScrollView.
Okay, I found the answer. I needed to set Autoresize Subviews to false on the UIScrollView. Having done that (by un-checking the appropriate box in IB) everything seems to be working fine.

Resources