Setting an image above of a UITableViewController - iphone

Iam currently working on a iPad project where i build my code on top of the premade "Split View-based Application".
I am trying to place a image above of the UITableViewController when i rotate my iPad into landscape mode, however i do not know if it is possible without having the image appear in the popover-menu when displaying in portrait mode.
I can't place a UIImageView inside IB, so trying to do it from the code.
Here is a image of my table: 1

Create and position the image programaticaly when initializing the view, and implement the following method in the view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
imageOverTableview.hidden = !UIInterfaceOrientationIsLandscape(interfaceOrientation);
return YES;
}

Related

First UIView not autosizing to fit iPhone 5 or iPad

I have a simple app with multiple UIViews. I've recently begun work to create a universal app out of it get the auto-sizing and rotation of views working with the iPhone 5 and iPad.
On my very first view, the view comes up as the standard 3.5" display with a white bar beneath it on the iPhone 5 (and beside it on the iPad). There is also a toolbar attached to the bottom of the view and it appears at the place where it would be on a 3.5" display. The strange thing is, when I go to another view and then return to the root view, the view is sized correctly.
I've checked my autosizing for the view - all outside and inside anchors are activated. My view mode is set to "scale to fit," and in comparison to other views, settings are the same. And the strange thing is it comes up right the second time the view is displayed.
Any thoughts?
I found my problem. It was in the didFinishLaunchingWithOptions method of the application.
I changed:
UIView *rootView = self.rootViewController.view;
CGRect rootViewFrame = rootView.frame;
rootViewFrame.origin.y +=[UIApplication sharedApplication].statusBarFrame.size.height;
to
UIView *rootView = self.rootViewController.view;
CGRect rootViewFrame = [[UIScreen mainScreen] applicationFrame];
The app was picking up the hard coded size of the view from the XIB when the view first loaded; now I just fit it within the application frame.

UI Page controller adjusting to just landscape mode XCODE

recently I found a project with a page view controller which I really liked and decided to use in my own project.
http://www.wannabegeek.com/?p=168
The problem is, The page controller starts out in portrait and has an auto rotate feature to landscape. For my purposes, I don't need any auto rotate feature, I just want to be able to swipe back and forth between views in landscape mode only.
I tried changing the code, but was unsuccessful in making it landscape only, If someone could help edit the code to NOT auto-rotate, start in landscape, and stay in landscape that would be great!
Thank you.
You have to perform 2 changes :
set Initial Orientation to Landscape ( either Home button left / right )
set - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation to return NO
Lemme add more detail to Shivan's answer:
Select Landscape Left and Landscape Right in target. Tap on the project to get to this page.
2.In the ViewController.m look for shouldAutorotateToInterfaceOrientation, make it return NO. See the following code.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}

UIWebview in a modal view is being shown in portrait in Landscape mode

I browsed through most of the questions and tried almost everything. But bad part is that the issue is still there.
I have a UIVIew which is always launched in landscape mode and I am presenting a second view (detailView) as a full screen modal view.
The detailview has a UIwebview on top of it.
When I present the detailView as a modal view, the webview is being shown in portrait mode.
I am returning "YES" in shouldAutoRotateToInterfaceOrientation and also have set autoresize , autoresizingMask and scalePageToFit properties.
When I rotate the device, and when the detailView is in front, the webview arranges to landscape properly.
The issue is only when I present the modalView for the first time.
Rotating the device is adjusting the layout properly.
As far as I am aware ModalViews on the iPhone do not support Landscape View. The case may be different for iPhone 5.
But it sounds like you are setting the ModalView not the WebView to landscape, I'd suggest a different approach to handling this.
For Example you could animate the DetailView in like a ModalView so it starts in the correct orientation
If you are running your app on iOS 6 you will need the following code in the modal view controller to support the landscape orientation:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL) shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
Also, make sure you are testing on the actual device as opposed to the simulator because auto-rotation behaves differently on the simulator.
That will do the trick:
CGAffineTransform transform = CGAffineTransformIdentity;
webView.transform = CGAffineTransformRotate(transform,-M_PI/2);
OK. First of all, the question I had posted was not clear. My question was that, when I load a webview, in portrait, it was loading the webview elements in landscape mode(CSS), and was getting loaded as portrait mode(CSS) in landscape orientation.
Turns out that I was not applying the correct CSS style.
The fix I did was:
In ViewDidLoad and willAnimateRotation method, I am posting a notification to my javascript to update the style based on orientation :)

UI ScrollView Hiding in iPad Landscape mode

I have added one UIScrollView and 2 UIImageView into it. It shows up fine in potrait mode. But it hides it in landscape mode. I am running from xcode n simulator and implemented the method - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation.
I am new to iPad programming and lil stuck. Appreciate any help.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
[self.view insertSubview:scrollView aboveSubview:imageView];
}
else
{
[self.view insertSubview:imageView aboveSubview:scrollView];
}
return YES;
}
The problem seems to be the autoresizing of these views you've added. If you created them from Interface Builder go to the fifth tab on the right panel and select a view, there you can set the view to adjust it's size and position when the parent view changes it's size (which is what happens when you rotate the device). If you created these view from code you should set the autoresizing mask (use the method setAutoresizingMask:), you can add several values to obtain the desired effect.
hope this helps!

UIScrollView landscape problems

I'm playing around with the page control sample code.
I changed the code to start the app in landscape, the app opened in the simulator but the app was still in portrait mode in a horizontal simulator.
I then put the following code into the PhoneContentController.m file and the MyViewController.m file and changed the MyView.xib view to landscape.
- (BOOL)shouldAutorotateToInterfaceOrientationUIIn terfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrienta tion);
}
Now what happens is the app starts in landscape mode with the first image displaying correctly. The problem now is the other images are showing on their sides and the scrollview is scrolling vertically instead of horizontally.
How can I get this to scroll horizontally in landscape mode with all the images also in landscape mode?
The ContentController and PhoneContentController classes are not subclasses of UIViewController. Therefore adding shouldAutorotateToInterfaceOrientation to these classes has no effect.
The rotation event is sent only to the first UIViewController that is added to the window (actually its view is added). In your case, shouldAutorotateToInterfaceOrientation is only called for the first MyViewController which is a subclass of UIViewController. Therefore only the first image is rotated.
To make it work properly you need to find a way to change ContentController such that it extends UIViewController.