更改了框架當應用程序連接到服務器時,出現一條小消息。 它在應用程序啓動時運行良好,並且應用程序需要顯示此消息的其餘時間,但如果我睡覺應用程序,則將其放在背景上,然後將其喚醒,然後再次顯示該消息但整個框架向上移動,看截圖。 第一個在啓動後立即顯示,底部的消息出現並消失,視圖恢復到以前的狀態,完美。當「applicationDidBecomeActive」
但第二截圖是使應用程序去背景,然後將其喚醒,上的結果的「applicationDidBecomeActive
」我有需要連接如服務器,因此小視圖的方法必須出現。問題在於窗口或navigation controller
在狀態欄後面向上移動。和離開該空白
繼承人,我使用,使短導航視圖,並添加消息視圖,並再次使延長它的代碼。
- (void)addMessageView:(NSString *)message{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if(![window viewWithTag:3]){//Si no hay un messageView no lo meto.
[window addSubview:messageView];
CGRect frameWindow = window.frame;
int heightMessage = 50;
messageView.frame = CGRectMake(0, frameWindow.size.height, 320, heightMessage);
UINavigationController *nav = window.rootViewController;
//Pillo el UILabel y lo seteo
UILabel *label = (UILabel *)[messageView viewWithTag:1];
label.text = message;
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize sizeMsg = [label.text sizeWithFont:label.font constrainedToSize:maximumLabelSize lineBreakMode:label.lineBreakMode];
UIActivityIndicatorView *activity = (UIActivityIndicatorView *)[messageView viewWithTag:2];
int xLabel = (320 - (sizeMsg.width + activity.frame.size.width + 5))/2;
CGRect frameActivity = activity.frame;
activity.frame = CGRectMake(xLabel, 13, frameActivity.size.width, frameActivity.size.height);
label.frame = CGRectMake(xLabel + activity.frame.size.width + 5, 15, sizeMsg.width, sizeMsg.height);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
nav.view.frame = CGRectMake(frameWindow.origin.x, frameWindow.origin.y, frameWindow.size.width, frameWindow.size.height - heightMessage);
messageView.frame = CGRectMake(0, frameWindow.size.height - heightMessage, 320, heightMessage);
[UIView commitAnimations];
}
}
,並把它恢復到原來的位置: - (無效){hideMessageView
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UINavigationController *nav = window.rootViewController;
CGRect frameWindow = window.frame;
if([window viewWithTag:3]){//Si no hay un messageView no lo meto.
[UIView animateWithDuration:0.3
animations:^{
nav.view.frame = CGRectMake(frameWindow.origin.x, frameWindow.origin.y, frameWindow.size.width, frameWindow.size.height);
messageView.frame = CGRectMake(0, frameWindow.size.height +5 , 320, 0);
}
completion:^(BOOL finished){
[messageView removeFromSuperview];
}];
}
NSLog(@"Tam Window: %@ y nav %@", frameWindow, nav.view.frame);
}
讓我知道你怎麼想。
您是否找到任何解決方案? – Pion
其實不,我嘗試了幾件事,但我無法弄清楚爲什麼它做到了這一點 – subharb