Positioning of view is different at application startup - ios5

I have an app which has a UITabBarController, and when different tabs are pressed, I override viewWillAppear, get a reference to the tabBarController and then resize its frame. The reason for doing so is that some tabs require the full height of the screen, whilst other tabs have a background in the top 120pixels.
The way I am referencing the tabBarcontroller is by getting the application delegate and using its reference to the tabBarController to move its position:
MyAppDelegate *del= [UIApplication sharedApplication].delegate;
del.tabBarController.view.frame = CGRectMake(0,120,320,360);
This method works fine when switching between tabs, but the first time the application loads up it does things a bit weirdly, and I cant understand why. My first tab actually has a NavigationBar, and then contains a view which has a pickerView. The first time my application loads, the NavigationBar appears about 10px too low, however the pickerView still appears in the right position. I was hoping I could get around this by treating things differently the first time viewWillAppear is called, however if I decrease the y position to compensate for the navigation bar, it shifts everything together including the datepicker within the view.
I would like to understand why the application behaves differently when first loaded and was hoping someone could either explain this to me and with any ideas on how to solve the issue or please point me in the right direction. I suspect this has something to do with the status bar on top since that is about the same size as the offset I am seeing..
Any help would be appreciated!
thanks

OK I've figured it out. If anyone is interested, it appears that on application startup, the UINavigationBar's frame has a y position of 10 pixels. All I had to do was set the UINavigationBar's frame vertical position back to 0 pixels and all works! Anyone needing to do this, here's the code:
self.navigationController.navigationBar.frame = CGRectMake(0,0,320,45)
I call the above line in the viewWillAppear method and all works as expected.

Related

UISegmentedControl Not Redrawn

I'm using a UISegmentedControl to show headers for a table view. When the orientation changes, the headers are resized depending on the labels in the table view underneath. Despite being connected up in IB, I have to move the phone around a bit to fire a orientationChanged notification and update the widths. I've even tried setting the first segment width to 0 in IB, then again in viewDidLoad, but all headers are the same width when the view loads. I've tried using performSelector:afterDelay to make sure the view is actually on screen, and also calling setNeedsLayout and setNeedsDisplay, but nothing seems to work. I simply have to jiggle the phone around.
Is this a bug anyone has experience with or am I making a daft mistake?
I'm setting the width as below:
[segSortOrder setWidth:0.0 forSegmentAtIndex:0];
The only solution I came up with for this was to use performSelector:afterDelay and using self.view.bounds.size.width with a variable amount of padding (how much is trial and error for each ViewController. Not ideal but it does the job.

Navigation bar title jumping right after flip transition

I have a simple UIViewController with a simple view. As a result of a user interaction, a new UINavigationViewController is instantiated and its view is being added as a subview to the view of the UIViewController. This takes place as part of an aninmation transition (flip).
This works quite well and the first view is flipped over in favor of the second view. But when the animation comes to an end (the UINavigationViewController's view fills the whole screen) the navigation bar items jump, i.e. the title jumps about 5-10 pixel from right to left, the buttons' jump depending on which side (left / right) they are positioned. During the animation you can see that the buttons are misplaced and that the jumping movement is kind of a repositioning.
Could anyone tell me the reason for this and give me some advice how to avoid this?
This is a little late, but there's no accepted answer and I've encountered this issue even fairly recently (albeit with an older app running on iOS 8).
If you encounter this issue and also see a warning along the lines of the following, it may be that you haven't properly set your root view controller in the app delegate:
Application windows are expected to have a root view controller at the
end of application launch
Modifying the app delegate as follows recently remedied the issue for me:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Other logic goes here
// ...
self.window.rootViewController = myRootViewController; // This was missing
[self.window makeKeyAndVisible];
return YES;
}
(I previously had some nearly-equivalent code that was setting up the view so everything displayed correctly on launch, but was not specifically setting the window's root view controller.)
I know it's annoying, but I have no idea why it happens, but in my experience, it happens in one of two cases:
Translucent navigationBar: maybe it had something to do with the fact that a translucent navigationBar sometimes sets a view's wantsFullScreen property (the view will then extend below the navigationBar).
During transitions: as you have described.
To avoid it, maybe a nice animation to fade it on an off screen before and after animation so as not to give the illusion of low quality.
OR
In viewWillAppear, assign the pixel value it's jumping to the navigationBar's origin.y. It's sad that it happens, but sometimes it just can't be fixed any other way.
This can be caused by partially-corrupt PNGs used for navigation bar buttons when the UIImages are resizableWithEdgeInsets:. If you're using custom button item images, try exporting them again using techniques known to produce reliable images (See blog posts by Marc Edwards at Bjango for a good start).
I recently had a problem that sounds identical to what you were experiencing. I found that using the [UIView performWithoutAnimation:^{}] block inside of transitionWithView fixed it.
During custom segue transition, view's navigation bar items are misplaced.

presentModalViewController:animated:NO displaying 20 pixel gap

I begin with a view-based app template. In the automatically created viewcontroller's xib (call it VC1), I add a button, and define in its interface/implementation:
- (IBAction)showVC2;
- (IBAction)showVC2 {
[self presentModalViewController:[[VC2 alloc] init] animated:NO];
}
I then create VC2. In both implementations, I allow only landscape orientations. In both xibs, I set the views to landscape. In the info.plist file, I specify starting orientation as landscape right.
When I run the project in the simulator and press the button in VC1, VC2 is displayed, but a 20 pixel gap shows both on the lower edge and on the right edge. Notably, rotation causes the view to be placed correctly on screen after rotation completes.
This issue is similar to others:
1 2 3, though the solutions identified do not seem to work in the present case. The correct/expected behavior occurs if the modal view is presented with animation (I do not want the transition animated, however). This issue has persisted since last summer (iOS 3.1.3?). It continues with 4.3. The issue does not occur in portrait orientation.
Can anyone provide a solution or explanation for why such a simple modal viewcontroller presentation does not give the expected result?
EDIT: Xcode project
I just tried building what you suggested and have no problems with a gap. I don't know if there is a way for you to post all of your code or your project. If you can do that I will try and help.

displaying a smaller UIWebView as a form sheet

I'm trying to pop up a UIWebView on iPad with a web site that is specifically sized for the iPhone (320x480). I want the web view to be centered, and transition in using a zooming animation. Other apps have this functionality, but I can't seem to find out how to do it. I've tried various combinations of presentation & transition style, but no matter what I do, the web view takes up the entire screen and slides vertically to cover the screen. I've made the web view 320x480 in IB, and am using UIModalPresentationStyleFormSheet, which should make it at least slide up into the center of the screen using a small window, but that is not occurring.
anyone know what's wrong?
Are you setting the property of the parent UIViewController or the modal UIViewController? Because you should be setting the properties of the modal UIViewController before presenting the controller instead of the parent.
This might be no help at all because you're doing the right thing, but it was the first error I made when starting to use MVCs.
maybe any of the autosize property is set. just do one thing bind your webview with the code and through code try to set the frame. Hope it will work as it worked many times to me when i faced similar types of problem.
hAPPY cODING...

How to implement view sliding in and out in iPhone?

I would like to implement the effect of a view sliding in, much like the animation of a view being brought in by presentModalViewController, but the view only slides in to cover half the screen.
I approached it this way:
1) Right before thew view should appear and slide in, addSubview the child view. Position it in such a way it's out of view in the beginning.
2) Call a method on the view controller of the subview to perform the Core Animation code to bring it in.
Doing the above didn't seem to work (nothing happens - the view just appears at its starting location). Adding the view ahead of time in viewDidLoad won't work either. Ideally, I would like the code to have the same requirement as presentModalViewController - which requires you to instantiate the view controller at the point you need to bring the view in and animate it.
Would appreciate if you can provide pointer or code on animating the view in/out as well.
I would check out the sample project ViewTransitions on the Apple dev site. It is a great resource for understanding the simple things you need to do when setting up transitions. If you wanted to only slide in half-way you could try setting the frame of the "sliding view" to only half the screen... just check out the code and give it a try.
I usually animate modal screen in the parent viewController instead of modal viewController itself.
Maybe you should post the code you use in step number 2.
I did something similar on one of my apps, where the user slides a view from one edge of the screen to the other as if placeing a cover over the screen.
If what you are trying to do is an automatic animation (without user interaction) I believe that you need to: set to the sliding view a frame representing the final position. Do this within an animation block. Play with the duration, animation curve, etc parameters.