I have a UIToolbar set up in my view controller that has a width of 768, extending across portrait view as I desire. But when I rotate to landscape, the toolbar maintains the same width, instead of extending to 1024 pixels.
I'm probably missing something obvious, but I can't seem to figure this out. Any ideas? Thanks.
You need to add Horizontal Space constrains as below:
Related
It gives me the following warning: Need constraints for: Y Position or height. I can get it working with for example TextView, by disabling "Enable Scrolling" but ImageView does not have a setting for something like that. I've also tried selecting my view controller and enabling/disabling "Adjust Scroll View Insets" which gives no results.
EDIT Image of my hierarchy.
The layout is ambiguous, because AutoLayout does not know the height of your UIImageView instance. Constraining views against a UIScrollView is somewhat special, because the ScrollView's contentView needs to calculate it's size based on the subviews. To to this AutoLayout needs to be able to calculate the dimensions of all the subviews without relying on the ScrollView's size.
There are different ways to solve this.
Add a explicit height constraint to the imageView
Add a aspect ratio constraint to the imageView
Set a placeholder intrinsic content size in the Interface Builder
This is a very simple ViewController. I have an imageView inside a scrollView. Using autolayout I set scrollview's constraints to its view's edges. Also, imageView mode is AspectFit.
The image is provided at runtime, and it may be a landscape or portrait size. When I run the app, the image doesn't fit the current screen size. It seems that scrollView's boundaries are not being honored, thus only part of the image is being displayed. It used to work on ios7 and xcode5, but it's broken for ios8 xcode6.
Any ideas? I need to keep the use of autolayout whenever possible.
Your going to set the imageviews horizontal constraints and pin them to self.view (the scrollviews parent view) instead of the scrollview.
There is a good example of this here:
Using UIScrollView with Auto Layout in iOS
Try this to zoom out completely
[self.scrollView zoomToRect:self.imageView.frame animated:YES];
Have you tried a call to imageView.sizeToFit() in viewDidLoad? My impression is that imageView's size is fluid until the outlets are set. A call to sizeToFit forces the issue.
In my app I want to provide text scaling in layer backed NSTextView like Apple's TextEdit. I use analogue of it's ScalingScrollView. Also I need to create some CALayer overlays on self.window.contentView. All is ok until I make [self.window.contentView setWantsLayer:YES].
Before [setWantsLayer:YES]
After [setWantsLayer:YES]
I haven't any ideas how to fix this problem.
I've been searching for the solution to the similar issue, too. Finally, I discovered that layer-backed views must be positioned on integral pixels and must not be positioned on subpixels.
E.g. if you dynamically calculate frame of layer-backed view
NSMakeRect((self.frame.size.width - 350)/2, (self.frame.size.height - 150)/2, 350, 150)
you may encounter non-integral values, so you should do something like
NSMakeRect(floor((self.frame.size.width - 350)/2), floor((self.frame.size.height - 150)/2), 350, 150)
At the moment the UIView is set to scale to fit. Is there any way of setting it to fill the whole element and set it to centre?
There is a content scale mode called aspect fill maybe does what you want.
I create a UIScrollView, in which I put a UIView. Then I add some objects which are subviews of the view I added to the UIScrollView, so that I can zoom properly all the objects within the scroll.
The point is that I have an UIImageView as a subview of the mentioned view, which contains an image which is adapted to the screen size by using "imageView.contentMode = UIViewContentModeScaleAspectFit;" property.
Initially, in portrait orientation, the image fits with the screen width, so you can't scroll to left or right. When I change orientation to landscape, image fits with screen top and bottom. Then my problem. You can scroll up and down a little bit the image, as if it preserved some of the top and bottom padding from the portrait orientation.
But, if I try to zoom out, as the min zoom I setted was 1,0, the image recovers its initial size. Then you can't zoom out anymore when the zoom scale is 1.0. The 'virtual' padding is gone!
It seems as if it needed some kind of refresh.
The same happens when I keep changing orientation for portrait and landscape. It only works correctly when app loads.
I tried setting "myUIScrollView.zoom = 1.0;" in "didRotateFromInterfaceOrientation" method (when the image was not zoomed) and it worked, the 'virtual' padding again was gone.
It seems that it needs a refresh once orientation changes.
Any clue about what I'm doing wrong?