Working with Landscape Views designed with interface builder - iphone

I'm trying to understand something that , by googling around, seems like a bug in the iPhone sdk, but maybe its just something hidden im not sure of.
I designed a new view in Interface Builder, in landscape mode. It looks like this:
But when i load it in from one of my other views, even though it is landscape, all the content doesnt look as it looks inside interface builder, it looks like this:
I found some code in google that helped to sort-of fix this issue, but the solution isn't perfect , and honestly its just kind of an ugly workaround, the code is (in viewDidLoad):
// First rotate the screen:
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
// Then rotate the view and re-align it:
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation( 1.570796327 ); // 90 degrees in radian
[self.view setTransform:landscapeTransform];
This code actually almost completely solves the problem, but still doesn't look exactly like my XIB:
I'd love to know if any of you creative minds have a better solution for this, and if not, if you can help me change the code above to maybe come closer to the "original" design in the xib file.
Thanks in advance! :)
Shai.

The reason your view is being pushed up is because the it's starting in the left top corner behind the status bar. Try adding this after the rotation:
landscapeTransform = CGAffineTransformMakeTranslation(0, 20);
[self.view setTransform:landscapeTransform];

Related

Iphone: Page flipping animation

My code is flipping my view as if you were reading a book in reverse page order (right to left). I'm trying to achieve the opposite but I can't seem to figure out how to make the page flip from the other side of the views coordinate system.
Here's my code:
_memoryOneView.layer.anchorPoint = CGPointMake(1.0f, .5f);
_memoryOneView.layer.position = CGPointMake(_memoryOneView.layer.position.x + _memoryOneView.bounds.size.width/2.0f, _memoryOneView.layer.position.y);
[UIView animateWithDuration:.5 animations:^{
_memoryOneView.layer.transform = CATransform3DMakeRotation((M_PI / 2.0), 0, 1.0f, 0);
}];
I've tried making many of the values negative but this simply hides the animation behind views behind it. Any ideas? ty.
Edit I also need to be able to use this animation for dragging, meaning I need to have something I can easily transfer into code where the user is dragging to the next page.
iOS 5 has an in-built PageViewController exactly for this. Tutorial here: http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_UIPageViewController_Application

EGOTableViewPullRefresh and landscape orientation

I am using Cocoanetic's implementation of EGOTableViewPullRefresh.
It's a cinch to implement. Love it:
http://www.cocoanetics.com/2009/12/how-to-make-a-pull-to-reload-tableview-just-like-tweetie-2/
The only problem I'm having is with rotation. When the view rotates, the refresh header doesn't adjust for landscape mode. It sits left aligned, 320.0f units wide.
I have tried everything I can think of to adjust this properly. I set it as a property in PullToRefreshTableViewController and tried to set the frame the same way it is done in init. This failed. I tried to do it in this same controller in viewWillAppear. Failed.
Beyond this, I tried about 6 other methods not worth detailing. The problem seems to be that I'm using the wrong bounds, even though I'm making them relative to the view.
Nothing I do replicates what is seemingly easy in viewDidLoad:
refreshHeaderView = [[EGORefreshTableHeaderView alloc] initWithFrame:
CGRectMake(0.0f, 0.0f - self.view.bounds.size.height,
320.0f, self.view.bounds.size.height)];
It seems all I really need to do is increase the width. I tried something along the lines of this:
refreshHeaderView.frame = CGRectMake(refreshHeaderView.frame.origin.x, refreshHeaderView.frame.origin.y, 480.0f, refreshHeaderView.frame.size.height);
No luck.
The link at the top has the full, unmodified source code for what I'm using.
What about just setting the UIView.autoresizingMask to UIViewAutoresizingFlexibleWidth?

UIScrollView scrollRectToVisible isn't doing anything

I'm not really sure why this isn't working, hopefully you can help me find the missing piece. I have a UIScrollView with paging enabled. I'm using it for side-scrolling through a tutorial. I have a button that when tapped should scroll the user back to the beginning of the tutorial. I originally tried using the scroll view's frame as the rect to scroll to because that CGRect should represent the first page. I've tried a couple of different CGRects to no avail though.
- (IBAction) touchedButtonReturnToBeginning:(id)sender {
// I've tried several CGRect's, none of which cause the UIScrollView to move.
// CGRect beginning = self.containerScrollView.frame
// CGRect beginning = self.containerScrollView.bounds;
CGRect beginning = CGRectMake(0, 44, 1, 1);
[self.containerScrollView scrollRectToVisible:beginning animated:YES];
}
I have verified that self.containerScrollView is hooked up in my xib as well as the touchedButtonReturnToBeginning action is connected to my button. I've used my debugger to step through this method, so I have verified that it is getting called. All of the variables are appropriately set, but when I call scrollRectToVisible the scroll view just doesn't do anything.
Any ideas?
I don't know why that wouldn't work, but have you tried [self.containerScrollView setContentOffset:CGPointZero animated:YES]?
To make scrollRectToVisible works check your self.containerScrollView.contentSize. It should be big enough :)

Two related questions about iPhone autorotation

1) Is it possible to change the speed of autorotation on the iPhone?
2) Is it possible to time an animation to take place during the autorotation animation? I would like to resize a photo while rotation is occuring, rather than when it's done.
1) not that I know of
2) Yes, see this method:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW53
As for the first question, I haven't used this but check it out:
[UIApplication sharedApplication].statusBarOrientationAnimationDuration = [NSTimeInterval ...];
See docs for UIApplication. The problem is that I don't know that this actually rotates the rest of your views. You may, however, be able to rotate the window's coordinate system around "manually" using UIWindow and [UIView beginAnimations ...] in order to recreate the whole effect.
Please post sample code somewhere if you get it working!

View not completely covering the entire screen

Once again I've searched for about 45 minutes for an answer to this question and I thought I might have found the answer but then the situation I was reading wasn't exactly like the one I'm running into.
when I add my view it seems that it's not completely covering the window I was able to get rid of the status bar at the top but there is a section of space at the bottom that the view is not covering
alt text http://img177.imageshack.us/img177/8844/picture1zjv.png
as you can see from the screenshot there is an orange bar...it's orange because I know what it actually is under there (it's the viewController's view but everything I try I can't seem to get the added view to cover the screen.
this is the only code that's run
(void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:mainMenu];
}
Any help would be appreciated.
There are a few things that might be going wrong:
Your frame might be too short. In viewDidLoad: you can add a debug statement to check its height:
NSLog(#"Height is %f", self.view.frame.size.height);
It looks like you want that value to be 480, the full height of the screen.
Your origin might be too high. Similarly check your y offset:
NSLog(#"y origin is %f", self.view.frame.origin.y);
It looks like you want that value to be 0.
The origin of your superview might be too high. Assuming you this view only has one superview, this code will help check the absolute coordinates of your view's origin:
CGPoint absoluteOrigin = [self.view convertPoint:self.view.frame.origin
toView:self.view.superview];
NSLog(#"y origin in superview is %f", absoluteOrigin.y);
You can just tag on a few extra .superview's to find out the coordinates in terms of the prior views.
By the way, instead of just using 480 as a magic number in your code, you might want to do something like this to get the full height:
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat screenHeight = appFrame.size.height;
The applicationFrame property takes into account whether or not the status bar is displayed.
You should post your code, but in general, you can make a UIView fill the screen as follows:
UIView *foo = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
And you can set the frame later:
foo.frame = CGRectMake(0,0,320,480);
To fill the screen, you should use a 320 x 480 Rectangle, at origin (0,0). That's what that CGRectMake function above creates.
I've had this problem before, I fixed it by just moving the view down 20 pixels...
When you use interface builder it has that nifty little "simulate status bar" or "simulate toolbar" feature but I think its kind of finnicky.
Both Andrew and Tylers answers should work though, no shame in doing things programmatically :). If you are creating the stuff in interface builder, just do Andrew's second line though, don't need to reinitialize.
Ok, well I figured it out and now I feel kind of stupid...I went back to IB and realized that the height of each view was set at 460 and not 480...you guys did give me a bunch of good information and I appreciate it all. I wish I could mark them all as answers.
Thank you again,
BWC