UIViewAnimationTransitionCurlUp with transparent background - iphone

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];

Related

UINavigationController - Keep Background Image Across All Views

Is there a way to have a background image remain constant across all views in a navigation controller? Currently I am loading the same background in each view's viewDidLoad method but this shows the background image move when navigating from view to view. I'd rather just the content of the view infront of the background "slide" on/off screen, but the background stay stationary. This is my current background image loading code:
UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
background.image = [UIImage imageNamed:#"InfoBackground.png"];
[self.view addSubview:background];
[self.view sendSubviewToBack:background];
[background release];
Thanks!
Hm, perhaps if you look at the documentation (scroll down to Figure 2) you will get an idea of what you're dealing with. Because you are setting the background image for each of your view controllers that are being pushed into the UINavigationController, you will get that animation. What you need to do is set the background image into the nav controller itself.
I believe myNavController.view insertSubview:myImageView atIndex:0 should work. If your image needs to fill in behind the content view exactly, you could set the frame coordinates based on the coordinates and/or heights of the navbar and toolbar, which can be accessed through the navigation controller's properties. If not, just set the frame to the superview's bounds.
Let me know how it goes.
Edit: Oh, note that you would need to make sure each of your view controllers had transparent backgrounds.
i think the better idea is place background image on window and set all view's(all viewcontroller's view) background color to clear color [UIColor clearColor].
if you want background image static then there is only one way but i don't know that is possible or not, If we put image in window and make navigation controller transparent then it's stay static whatever you will do. because we are not changing window while push or pop.
I am just suggesting try this way i haven't tried like this.

How To Present Half Screen Modal View?

I have a UIViewController and when a button is pressed, I want a half screen view to slide up with a UIPicker in it.
I made a UIView in IB with the UIPicker along with a UIToolBar with Done/Cancel buttons.
How can I make it so that just this half view slides up and the background view is still showing but dimmed or cant be played with.
I'm using this code so far:
- (void)showModalView
{
[self.popupView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.popupView];
[UIView animateWithDuration:.2 animations:^{
[self.popupView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}];
}
Here is a pic: http://www.box.net/shared/static/08ji4s0f6i1b8qubrtz6.png
#Jon:
METHOD-1:
Make your main view transperant by setting its alpha value to 0 and add a subview to the main view which is only half of the main screen and keep it opaque (alpha value as 1) as it would be by default.
Then simply present the view controller using present Modal View Controller.
Keep in mind that because of the transperancy you would be able to see half of the previous view, but wont be able to touch it as there is a transperant view.
METHOD-2:
Another work around is to animate a UIView which is of size half of the existing view.
Then you have to simply follow animation of the UIView.
Here as it is just a UIView that will be added as subview to existing view, you will be able to touch the rest of the screen.
So you can follow either of the methods as per your requirement.
Hope this helps you.
Here is what u need its an open source code on github TDSemiModalView having a half view date picker. Check the demo project inside the code. Here is the link.. Hope it solves your problem.
TDSemiModalClass

Cannot properly rotate a translated UIView on the iPad

I have an UIViewController that has two UIViews inside, whose layout (set in Interface Builder) is something like this (the magenta colored view is the UIViewController default view):
and I added the main view to a root view obtaining this effect (by not showing the darker view placing its frame at the bottom):
Now when the device rotates, what I obtain is this:
whereas I'd like to still hide the darker view.
This is the code I use to hide it when it appears (I use it in the viewDidLoad method):
- (void)hideAll:(float)time{
CGRect hiddenFrame = CGRectMake(0, 1024, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame:hiddenFrame];
[self.view setNeedsDisplay];
}
and it appears to work, but when I call a variant of it when rotating (in willRotateToInterfaceOrientation:duration:), nothing happens:
CGRect hiddenFrame = CGRectMake(0, 748, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame:hiddenFrame];
[self.view setNeedsDisplay];
What am I missing? have I to set some other view property in Interface Builder?
UPDATE
It seems to me that the coordinate system does not change after the device has been rotated (ie the origin set in the upper-left corner in portrait mode will become the upper-right after a clockwise rotation in landscape mode)
Check your struts and springs in IB. It maybe that when you autorotate, the strut fixing you to the top of the screen moves your frame back to the top.
Try adding your code to the didRotateToInterfaceOrientation method so it can run after rotation has occurred.
Why to you change the frame to hide it, and not just
[self.view setHidden:YES];
second thing is that you should try to set the "Autoresizing" panel to handle the orientation changes, and not by changing the frame of the view.
hope i understood you right.
shani
The problem I encountered can be faced in two ways (I hope this can save some time for someone in the future):
using an UIViewcontroller (loaded from xib) and only its view as the rotating view, that is my original attempt to solve it. In this case you have to programmatically set the frame for the view when you want to hide it, and by doing so you have to consider that the coordinate system for the controller remains untouched and does not rotate (ie. it is always originated from the same corner)
using a UIView (loaded from xib) inside an already existing UIViewcontroller, in this way the view will automatically rotate and resize and you will not have to take the proper coordinates value into account at each rotation (this is by far the simplest way)

UIWebView won't fill screen

Edit: This was a result of my own stupidity - the website I was liking to (iphone optimised) was not resizing to take advantage of the extra space, other pages display full screen.
Hi,
I've been trying to create a view that has no navigation bar, just a UIWebView that takes up the entire screen with a button to exit the view. I've managed to find a solution to hiding the navigation bar, but the problem is, it leaves a 44px space at the bottom of the view. So what I have is a webview taking up 460px on the screen, then just a white area below.
In Interface builder I tried to edit the size of the view but it was greyed out and set to 460px. Is there a way to make it so the webview takes up all 480px?
Thanks for any suggestions.
Chris
You can set the size of UIVewView programmatically in this way:
myWebView.frame = CGRectMake(0, 0, 320, 480);
and place it by example in viewDidLoad method.

iPhone Horizontal Scrolling

I am trying to create an app with horizontal scrolling, so that one would be able to scroll horizontally through a series of images. I watched the WWDC Session 104 video on this, and while they made an interesting app, they flew through the basics of it very quickly.
I understand using the UIScrollView, and that I have to enable paging. After that they say that I should add more views as subviews of the scrollview, but I am not clear on how to do that. I am also not clear on how I add my images to those views.
As you can probably tell I am pretty new at this so any help would be appreciated.
You want to look into UIImageView. It's a view specifically for holding images.
When you add your images, you want to set their rects (probably using initWithFrame: for each UIImageView) so that:
the first image is at 0,0
the second image is at 320,0
third is at 640,0 (etc)
I.e. each image is 320 pixels right of the previous.
The final step is to set the contentSize for your UIScrollView -- this is a CGSize which describes the total size of the scroll view.
If you have 3 images, you would then set it to (320*3) * 480 using e.g.
myScrollView.contentSize = CGSizeMake(320*3, 480);
A lot of people, when they initialize the scroll view, have a for loop or similar which steps through the images they want to display. These for loops tend to look something like this:
CGFloat scrollWidth = 0.f;
for (UIImage *someImage in someNSArrayWithImages) {
UIImageView *theView = [[UIImageView alloc] initWithFrame:
CGRectMake(scrollWidth, 0, 320.f, 480.f)];
theView.image = someImage;
[myScrollView addSubview:theView];
[theView release];
scrollWidth += 320.f;
}
myScrollView.contentSize = CGSizeMake(scrollWidth, 480.f);
This way you'll get things lined up and you'll get the content size for you at the same time.
If you want to make it so that the scroll view "intelligently" scrolls to each image and stops when people slide left/right, you can do myScrollView.pagingEnabled = YES.
Hope that helps get you going.
Assuming you have "infinite" images, putting them all there at or before launch time in a huge UIScrollView will not be an option. (there is a limit to the size of a UIView)
The way I solved it: Make a UIScrollView covering the whole screen. It's content should be a UIView of 3*320 width and 480 height, extending 320px left and 320px right.
Put 3 UIImageView's in it, left, middle and right. Set paging=YES, so the uiscrollview clips to the 3 "pages" you've created.
Make sure your class is the delegate of the uiscrollview, and listen for
-(void)scrollViewDidEndDragging:(UIScrollView*)sv willDecelerate:(BOOL)notFinished
-(void)scrollViewDidEndDecelerating:(UIScrollView*)sv
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView*)sv
and make the appropriate transitions on hitting paging boundaries; shift images and set ContentOffset so you're looking at the center image again.
I suggest you make this first, and only then read on...
Then you will hit on a bug, documented here UIScrollView - (bounces = NO) seems to override (pagingEnabled = YES) and here http://www.iphonedevsdk.com/forum/iphone-sdk-development/935-paging-uiscrollview.html, which makes that you cannot disable bouncing and have paging enabled at the same time. So enable bouncing, and subclass UIScrollView, overruling setContentOffset in there to prevent bouncing. (having bouncing really enabled will make for a rather unusual user experience)
Have a look at Apple's PageControl sample code. It's fairly short and easy to follow so you'll get the gist of setting up a project where multiple view controllers are loaded as you swipe horizontally.
Once you have this setup then it's the view controller's responsibility to load its own content (in your case, an image). You should make sure you understand how to load images first (using threads, etc) before you tackle paging, etc.
Think of it as two independent tasks. The view control is responsible for loading and displaying an image. The scroll view with paging just tells the appropriate view controller when to load itself (it doesn't care what the view controller does once its loaded)
Good luck!