UINavigationBar height is reducing after re-enteringforeground - iphone

My controller main view call
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
in it's viewDidAppearmethod because the screen must be manually rotated for the user.
Everything works perfectly except when I put the app in background and I re-enter foreground on this screen: Then the navigationBar's height become 32px.
If I comment the setStatusBarOrientation call, then no problem.
I've logged the navigationBar height in didEnterForeground method (after the super call), but it tells 44px. So I guess it would be resized after.
So I would like to know :
If there was a way to prevent the navigationBar to be resized
If no, what other callback method would come after the didEnterForeground one (viewWill/DidAppear does'nt)
Thanks !

After 4 months, I finally found a partial solution !
If no, what other callback method would come after the didEnterForeground one (viewWill/DidAppear does'nt)
I found a good callback when a viewController (not app delegate) is re-entering foreground. With NSnotificationCenter
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
don't forget to remove
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];

Related

how to call a presentModalView from a subView?

i'm working in ipad application,i have a viewController A which have many subviews viewcontroller b,c,d,e,f... when i want to select a cell from one of viewcontroller to have a prsent modal view "full screen" it's not working ,how can i fix that
as you have added all the viewcontroller as a subview you don't need to present it
you just try
[self.view bringsubviewtofront:a.view];
hope this help ,
EDIT
use following local notification calling methods to solve your problem,
//place in class from which you want to perform action
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(openLarge:)name:#"openLarge" object:nil];
//place in class where you want to perform action
[[NSNotificationCenter defaultCenter] postNotificationName:#"openLarge"
object:nil userInfo:nameDict];
regards,

Performing an action on one view, and the action doing something on another view? Is this possible?

I have 2 views:
OneViewController
TwoViewController
TwoViewController has an IBAction which plays a sound. Once the user has pressed the button on TWoViewController I want a UILabel which will appear on OneViewController saying that the sound has been played.
Thanks for the help
All you have to do is reference one viewController in the other one, that way you can call it's methods. Or you can simply create a delegate.
One possible solution is to use notifications.
In the action that plays a sound, post a notification to the default notification center that indicates the sound has played.
[[NSNotificationCenter defaultCenter] postNotificationName:"playSoundNotification"
object:self
userInfo:nil];
When OneViewController is created, have it register for the notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(showPlayedLabel:)
name:"playSoundNotification"
object:nil];
When it receives the notification -- in showPlayedLabel: -- display the UILabel. Note that showPlayedLabel must follow the appropriate signature format.
- (void) showPlayedLabel:(NSNotification*) aNotification;

iphone: Preserve view on top of mpMoviePlayerController

I have a mpMoviePlayerController, and I have subview on top of it. When the user taps the fullscreen button of the mpMoviePlayerController, the subview disappears, and only appears when I go back to the original size. Is there a way to keep the subview? Is there a way to get a reference of the "scaled" moviePlayer?
Quick Draft:
trap MPMoviePlayerWillEnterFullscreenNotification like this:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(MPMoviePlayerDidEnterFullscreen:)
name:MPMoviePlayerDidEnterFullscreenNotification
object:nil];
within MPMoviePlayerDidEnterFullscreen, add that subview onto the current keyWindow like this:
[[[UIApplication sharedApplication]
keyWindow]
addSubview:mySpecialSubview]

Iphone- How to resize view when call status bar is toggled?

I'm creating an iphone app with few elements inside the controller (e.g tab bar, uiview, uitoolbar, etc..). Everything works fine until I encountered this problem. While my application is launched, I received a call and it shows the "Call Status Bar" which ruined the ui. Some elements are pushed down because the "Call Status Bar" is taking space at the top.
Anybody here have an idea on how to fix this issue? I'm new to iPhone app development.
Your reply is greatly appreciated...
Best Regards,
dianz's solutio works just fine but is a bit redundant if you are only interested in knowing about the notification inside of a specific view controller.
After the delegate method application:didChangeStatusBarFrame: is called in the Application Delegate UIApplicationDidChangeStatusBarFrameNotification is posted through [NSNotificationCenter defaultCenter].
Instead of using the delegate method application:didChangeStatusBarFrame: to simply repost a custom notification you can add an observer to UIApplicationDidChangeStatusBarFrameNotification directly from your view controller.
In MyCustomViewController you would add something similar to this:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doSomething:)
UIApplicationDidChangeStatusBarFrameNotification
object:nil];
Now you no longer need to define the application:didChangeStatusBarFrame: delegate method in appDelegate (unless you plan to do something in the appDelegate when the status bar changes size).
As with dianz's example you need to remove the observer in dealloc
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
You should put this function on appDelegate, this will trigger when the status bar change
- (void)application:(UIApplication *)application didChangeStatusBarFrame (CGRect)oldStatusBarFrame
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:#"trigger" forKey:#"frame"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"trigger" object:self userInfo:dict];
}
This Code will send Notification with the name "trigger"
Place a code to your view Controller (e.g: viewDidLoad, etc..) this listen if there are notification send with a name "trigger"
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(dataReceived:)
name:#"trigger"
object:nil];
And create a function dataReceived:
- (void)dataReceivedNotification:(NSNotification *)notification {
NSDictionary *data = [notification userInfo];
// do something with data
}
do something on this part of the code, maybe you change the frame of your tab bar, uiview frame, toolbar frame
And in dealloc, put this code to remove the observer
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Basically what you normally do is try to set up the autoresize flags of all your ui elements in interface builder so that when the main view is "squashed" by the call status bar everything will still look reasonable. It's a little hard to explain how to do all of this in one message, but I recommend creating a view in IB, placing some subviews in it, then resizing the main view while playing with the autoresize flags to get a feel for how the flags work. The autoresize flags are in Command-3 (size inspector).
You can also set wantsFullScreenLayout in the main view controller to YES to cause the view to take up the whole screen, including the area under the status bar, but then you'll have to make sure not to place anything under the status bar and the call status bar will overlap anything too close to it, of course.
for me, whenever the status bar is enlarged, the -(void)viewWillLayoutSubviews is always called. This is perfect for me because all my subview setFrame code is in this function.

two UITextFields - slide first Keyboard out and next in

so in my viewdidload i got something like
[nameTextField becomeFirstResponder]
now after a button gets klicked, i want to slide out the keyboard of this textfield, and slide another keyboard of another textfield in.
i thought about
[nameTextField resignFirstResponder];
[dateTextField becomeFirstResponder];
but the other keyboard shows up immediately.
commenting the [dateTextField becomeFirstResponder]; out, effects that my nameTextField keyboard slides out as i wanted.
any ideas how to do this?
thanks!
Is there a reason why you want to do this? It will obviously increase the time it takes for a user to enter information, which I know would bug me.
But if you do really want this effect, then I would look at something like this:
[dateTextField performSelector:#selector(becomeFirstResponder) withObject:nil afterDelay:timeDelay];
Where timeDelay is the amount of time it takes to dismiss the first keyboard.
You can register to observe these notifications: UIKeyboardWillShowNotification , UIKeyboardWillHideNotification. That will let you keep track of what is going on, but it can easily get pretty complicated so Tom Irving's suggestion might be easier to work with.
To get notifications on keyboard hiding and showing, have a look at
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:[self view].window];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:[self view].window];
and add appropriate methods like
-(void)keyboardWillShow:(NSNotification*)notif
-(void)keyboardWillHide:(NSNotification*)notif
-(void)keyboardDidShow:(NSNotification*)notif
-(void)keyboardDidHide:(NSNotification*)notif
Then you can connect the animations any way you like.
Be sure to NSLog() all of them, they are not always called when you would expect them (the notorious one being when you go from one field to another, and you receive the willhide and willshow immediately)