Changing UIWebView frame without changing content size - iphone

I'm trying to animate a UIWebview being removed from the screen. I'm using an animation block to set the frame height to 0. That works fine, the problem is the content size of the web view immediately takes the new frame height. So the content disappears and the background animates off. How can I stop that from happening? Here's my animation block.
// Change frame height.
[UIView animateWithDuration:1.0f
animations:^ {
// Animate the frame to the full height
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 0);
}
];
Thanks

So if you want the content to remain where it is, you'll probably have to 'cheat' this.
Apple do this themselves on many transitions - if you go into slow animation mode on the iOS simulator, or on Mac OS you can see how it works. Unfortunately a UIWebView is very limited in scope for customisation...the only property that controls scaling is the scalesToFit value.
A different approach would be to capture the UIWebView as an image, replace the webview with that image (to the user this is seamless), and then perform the animation on the image itself. Since you're just changing the frame of a straight forward image you then won't run into any of these problems (you can also change the animation effect: if you image scales to fit the frame the content will be 'squeezed', or you can just have it cropped).

Related

AVCaptureVideoPreviewLayer cropping when resizing without animation

Problem: When changing frame of AVCaptureVideoPreviewLayer sometimes can see how image slowly changing it size.
Goal: Resize AVCaptureVideoPreviewLayer without cropping image (When setting the frame, immediately redraw the content, without middle state redrawings).
I created a method for easy resizing without animation and middle state redrawing.
But sometimes it doesn't work and an animation of slowly changing image size appears.
Example of problem:
Initial state Frame is not set yet.
Problem state The frame is set, but the image does not fit in it (I think because of CATransaction).
Result state Image fits within layer boundaries.
By default .videoGravity = .resizeAspectFill
But in this example before I setting frame (calling applyFrameToPreviewView method) I setting .videoGravity = .resize
Thanks

iPhone iOS large UIView gets clipped to 320x460 when displayed. How to prevent?

I have a 850x1100 UIView defined in a storyboard it is 4 times the size of a normal window, and I'm using it as a PDF generation template.
The view is wrapped within a scrollview. Yet when I display the view, its frame gets resized and becomes 320x460, effectively cutting off everything outside the frame.
Does anyone have insight on why my UIView defined in a storyboard as 850x1100 gets its frame reset to 320x460 when displayed on an iPhone?
This frame recalculation is not a bug. The frame of a view represents its position and size relative to the screen coordinates.
The iPhone viewing area is 320x480 and any view that has its frame set to a CGRect larger than the viewing area of the device will become "clipped" and have its frame set back to the viewing area (320x460 viewing area due to the status bar).
Try:
scrollView.contentSize = CGSizeMake(850,1100);
scrollView.clipsToBounds = NO;
pdfView.clipsToBounds = NO;
Are you sure it's not the scrollview whose contentsize is too small? It won't automatically resize based on the content - you have to explicitly set the contentSize of the UIScrollView

Scrolling a patterned background on UIView

I have a simple UIView which I'm filling with a patterned background, like this
self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"backgroundPattern"]];
I want to be able to manipulate the origin of the view by modifying its bounds property and have the background move with the change in origin (as if the background is fixed to the content, not floating behind it). Is this possible? Currently the background seems fixed to the view's frame instead of its bounds and the pattern doesn't scroll when the content scrolls.
To change the origin I'm using a block animation like this
self.bounds = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
[UIView animateWithDuration:1. delay:0. options:UIViewAnimationOptionRepeat animations:^{
self.bounds = CGRectMake(0, 100, self.bounds.size.width, self.bounds.size.height);
} completion:nil];
With that code, my child views repeatedly scroll and reset, but the background stays fixed in place. Is it possible to specify a background which scrolls with the view instead?
I haven't been able to find anything on making a background pattern "stick" to the view's origin system. My solution for my app has been to make a child view and set the background pattern on that. Then the child view will move with the origin change and the background pattern will follow it. The problem with that solution is that the child view has to be large enough to cover the range of potential origins, which can be difficult to handle if the content area might be arbitrarily large.
You could generate an instance of your view again in the direction the user pans and add it to an NSMutableArray to be accessed and moved based on the offset of the world.

UIViewAnimationTransitionCurlUp with transparent background

I'm implementing a fairly standard UIView animation, using UIViewAnimationTransitionCurlUp. The basic idea is that I have a folder on the screen covered with a stack of pages, and as I change from page to page I use the curl up animation. Each page is a subview that takes up about 70% of the screen so that the clipboard is still visible in the background.
This animation all works fine, that problem is that even though each "page" (which is a separate UIViewController & UIView) has a transparent background, the page background becomes visible during the page curl. It's only slightly visible, like a black background with an alpha of 0.1. But it ruins the effect.
Any ideas? This is for a private application that will not be distributed on the app store, so private APIs are ok.
You will need to change the size of the view of your page view controller to be exactly the size of your page image. It looks from your included image that your page is also rotated. You can apply a rotation to your view to match this rotation. Here is part of the code that I used to achieve the effect in the screenshot:
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
CGRect pageViewRect = CGRectMake(0, 0, 300, 586);
self.pageViewController.view.frame = pageViewRect;
self.pageViewController.view.transform = CGAffineTransformMakeRotation(-M_PI/30);
[self.pageViewController didMoveToParentViewController:self];

Problem animating size change in a custom-drawn view

I have a custom UIView that implements drawRect to render itself with a gradient background and a 1-pixel black border around the edge, and some text.
In my parent view controller, I am attempting to animate my custom view from its original small size to full-screen, using this code:
[UIView beginAnimations:nil context:NULL];
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGRect detailRect = CGRectOffset(screenRect, 0, -screenRect.origin.y);
[dayDetail.view setFrame:detailRect];
[UIView commitAnimations];
This works, but drawRect in my custom view is only called once when the view is initially created. As a result the resizing just takes the original small image and blows it up to full screen, so the border of the full-size view is now many pixels wide instead of one, and the text gets expanded in size as well.
Is there any way to set this up so that drawRect is called continuously as the view is being animated from small to full-screen? Basically, I want my custom rendering code to handle the appearance of the view no matter what size it is at any point in time.
I've had the exact same problem and this is how I solved it:
dayDetail.view.contentStretch = CGRectMake(0.5, 0.5, 0.0, 0.0);
That will stretch the middle pixel only. Read the documentation to learn how to modify that behavior. You could certainly ask me, but reading the documentation is probably quicker. Besides, I would probably just quote the documentation.