Swift Xcode aspect-fit behaviour using AutoLayout on a UIImageView inside a containerView - xcode

I have a embedded containerview inside my viewcontroller that leads to a UIPageController. Then the UIPageController loads images from a 3rd VC controller.
So it just a simple image swipe / image carousel.
What I cant get to work is autolayout on the UIImage. My containerview has a maring top 0 right 0 left 0 and a height of 200pt with aspect ratio set.
Bellow it some other information shows eg title / text etc.
But all images appears zoomed in/croped in the containerview.
So how can I make the images scale and fit inside the container view?
Thanks,

set the image view's contentmode to scale aspect fit to see as much of the image as possible.
imageView.contentMode = .ScaleAspectFit

Related

NSImageView rending a blurry NSimage despite it being of the same size

I have an NSCollectionViewItem with an NSImageView (32x32) to which i supply a #1x image of the same size.
It looks perfect in the interface builder, but when the app is built, the resolution looks quite off. Is there any particular reason for this?
Just to add that the Image in the asset manager also has a #2x
EDIT: Still investigating this issue, but I have just noticed that If the collection view which contains the collection item, which contains the NSImageView is enclosed by a bordered NSSCrollView the images are perfect (.ie non blurry)
Turns out if you draw images in frames with either the x,y coords or the height and width having fractions you end up with blurry images. passing the drawingRect through NSIntegralRect fixes that.

In Xcode 6, why is the Image View keep automatically resizing when I try to resize a subview within it?

Posted is a picture of my issue.
I'm fairly new to Xcode and I have a UIImageView object in my View. I added another View (white rectangular box) within the View, and below the UIImageView object.
If I try to resize the inner View in any way using the cursor, the Image View resizes to 0 as shown below. However if I use the Size Inspector (ruler icon) on the right to resize the subview, the Image View stays the same size. What the heck?
Is there some setting I need to adjust? Thanks

iOS 8 imageView inside scrollView with autolayout not working

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.

Resizing image view and movie player controller in xcode when orientation changes

In my app i have an image view in one view controller and a movie player in other view controller.Now i want to display the image or movie in both mode i.e in portrait mode and in landscape mode .How can i define frame for each and how do i notify it when the view changes its position from one to other.
Thanks,
Christy
MPMoviePlayerController.view.frame = CGRectMake(20,20,280,440);
imageView.frame = CGRectMake(0,0,320,480);
and image in UIImageView in center have transparent background
this is for iPhone
Checkout the documentation for UIViewController and look at the Responding to View Rotation Events Methods like: - willRotateToInterfaceOrientation:duration: You can put your code for setting the new frame sizes in those functions along with any notification functions you want. player.view.frame = CGRectMake(x,y,w,h);

UIView backed by CATiledLayer in UIScrollView doesn't scroll initially

I'm adding a CATiledLayer backed UIView in UIScrollView.
When the view is first loaded, I'm trying to fit the UIView, by setting the zoomScale of UIScrollView - this fits the UIView and the layered contents.
I'm having a method to fetch the tiles of image and I'm rendering them in drawLayer:inContext:
Now even if the contentsize of scrollview/frame of CATiledLayer view is greater than UIScrollView, it doesn't scroll initially.
The moment I try to zoom by pinching the screen, I'm able to scroll perfectly.
I can't scale the CGContext in drawLayer:inContext, since the context I receive is of a tile and not whole image and I have 20 tiles which make up my image.
At the end of the initWithFrame of the PDFScrollView i added the line:-
self.zoomScale = 1.0;
This worked for me.
The code is pretty much doing the same stuff as apple example
http://developer.apple.com/library/ios/#samplecode/ZoomingPDFViewer/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010281-Intro-DontLinkElementID_2
which also doesnt scroll on loading

Resources