Comment faire en sorte que mon affichage apparaisse sous la barre verte lors d'un appel téléphonique? En ce moment, mon application est partiellement couverte par la barre verte lors d'un appel téléphonique.Comment positionner la vue sous la barre verte pendant un appel téléphonique?
Répondre
Si vous Si vous utilisez Interface Builder, assurez-vous que vos masques autoresize sont définis de manière à redimensionner les vues au lieu de simplement les placer dans la même position. Vous pouvez utiliser l'option Basculer la barre d'état en cours d'appel sous Matériel dans le simulateur pour le tester.
Si vous n'utilisez pas IB, vous pouvez configurer les masques d'autoresize en code.
Si vous n'utilisez pas de vues, vous devez redimensionner vos graphiques lorsque vous recevez les notifications appropriées.
Vous pouvez savoir quand cela va se passer en utilisant les méthodes UIApplicationDelegate suivantes:
- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame {
NSLog(@"willChangeStatusBarFrame : newSize %f, %f", newStatusBarFrame.size.width, newStatusBarFrame.size.height);
}
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)newStatusBarFrame {
NSLog(@"didChangeStatusBarFrame : newSize %f, %f", newStatusBarFrame.size.width, newStatusBarFrame.size.height);
}
Alternativement, vous pouvez vous inscrire à une notification dans votre sous-classe UIViewController:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameWillChange:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
}
- (void)statusBarFrameWillChange:(NSNotification*)notification {
NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect newFrame;
[rectValue getValue:&newFrame];
NSLog(@"statusBarFrameWillChange: newSize %f, %f", newFrame.size.width, newFrame.size.height);
// Move your view here ...
}
- (void)statusBarFrameChanged:(NSNotification*)notification {
NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect oldFrame;
[rectValue getValue:&oldFrame];
NSLog(@"statusBarFrameChanged: oldSize %f, %f", oldFrame.size.width, oldFrame.size.height);
// ... or here, whichever makes the most sense for your app.
}
Notez que les suggestions ci-dessus se déclenchent également lorsque l'appareil est pivoté. Si vous voulez juste savoir quand la barre d'état a grandi en raison d'un appel entrant/en cours. J'ai trouvé le code suivant au travail:
AppDelegate.m
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
float adjustment = 0;
if ([UIApplication sharedApplication].statusBarFrame.size.height == 40)
{
adjustment = -20;
}
else if ([UIApplication sharedApplication].statusBarFrame.size.height == 20 && oldStatusBarFrame.size.height == 40)
{
adjustment = 20;
}
else
{
return;
}
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
{YOUR VIEW Controller - remove .view if a view}.view.frame = CGRectMake({YOUR VIEW Controller}.view.frame.origin.x, {YOUR VIEW Controller}.view.frame.origin.y + adjustment, {YOUR VIEW Controller}.view.frame.size.width, {YOUR VIEW Controller}.view.frame.size.height);
[UIView commitAnimations];
}
Idem avec une application barre d'onglets et iOS6/7, grâce à l » answeruser1208489.
Les valeurs sont complètement différentes et bizarres pour chaque iOS. ; OP
mainAppDelegate.m
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
float vue = 0;
float barre = 0;
float hauteur = 0;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 // pour Xcode5/SDK7
if ([UIApplication sharedApplication].statusBarFrame.size.height == 40)
{
vue = -20;
barre = +20;
}
else
if ([UIApplication sharedApplication].statusBarFrame.size.height == 20 && oldStatusBarFrame.size.height == 40)
{
vue = 0;
barre = -20;
}
else return;
#else // pour Xcode4/SDK6
if ([UIApplication sharedApplication].statusBarFrame.size.height == 40)
{
vue = +20;
hauteur = 1;
barre = -1-20;
}
else
if ([UIApplication sharedApplication].statusBarFrame.size.height == 20 && oldStatusBarFrame.size.height == 40)
{
vue = -20;
hauteur = -1;
barre = +1+20;
}
else return;
#endif
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
self.tabBarController.view.frame = CGRectMake(self.tabBarController.view.frame.origin.x, self.tabBarController.view.frame.origin.y + vue, self.tabBarController.view.frame.size.width, self.tabBarController.view.frame.size.height+hauteur);
self.tabBarController.tabBar.frame = CGRectMake(self.tabBarController.tabBar.frame.origin.x, self.tabBarController.tabBar.frame.origin.y + barre, self.tabBarController.tabBar.frame.size.width, self.tabBarController.tabBar.frame.size.height);
[UIView commitAnimations];
}
Testé sur 4S 7.0.4 (11B554a) avec Xcode 4.6.3 (4H1503) et Xcode 5.0.2 (5A3005).
- 1. Comment faire des actions visibles pendant un appel téléphonique?
- 2. Comment redimensionner une vue dès que la barre d'état redevient normale après un appel?
- 3. Android Handle appel téléphonique
- 4. aider à positionner la barre de recherche
- 5. Comment être averti lorsqu'un utilisateur ouvre mon application iPhone pendant un appel téléphonique?
- 6. Safari iPhone faire un appel téléphonique
- 7. Comment réinitialiser automatiquement un contrôleur de vue pour que sa vue commence sous la barre d'état?
- 8. Peut-on utiliser NSUserDefaults pour mettre l'application en pause pendant un appel téléphonique?
- 9. comment positionner la barre de défilement verticale en html?
- 10. Comment faire un appel téléphonique grâce à une programmation
- 11. Comment faire pour reprendre l'application iPhone après un appel téléphonique
- 12. Comment positionner la vue par rapport au parent?
- 13. Comment mettre fin à un appel téléphonique en C# CF?
- 14. Est-il possible d'empêcher iPhone Safari d'afficher la barre de navigation pendant un appel AJAX?
- 15. Appel téléphonique en utilisant un numéro dans un UITextField
- 16. Sous-vue est montrant la vue principale sous
- 17. Comment positionner un TabBar par programme
- 18. C#: Comment positionner un menuitem?
- 19. Comment positionner un UIView?
- 20. Comment empêcher la sous-vue de se superposer à la barre d'onglets?
- 21. Verrouiller un bouton pendant un appel AJAX
- 22. Évitez hardcoding taille de l'écran iPhone avec la création de vue programmatique
- 23. Comment ajouter une barre de recherche sous la barre de navigation dans un UISplitViewController?
- 24. Ajout de UITableView à la sous-vue lors de la modification de la barre de recherche
- 25. iPhone: UITableView défilement sous la barre d'onglets
- 26. automatiquement lancer App pendant iPhone Appel
- 27. Chargement d'une sous-vue pendant que mon sous-vue principale n'est pas chargée
- 28. Bouton Ajouter à la barre d'outils Internet Explorer pendant l'exécution
- 29. Comment positionner une ligne sous un groupe de tags?
- 30. UITableView défilement sous la barre de navigation
Vous pouvez même utiliser les extensions UIKit comme ceci: CGRect newFrame = [rectValue CGRectValue]; - d'une manière ou d'une autre! –
Je veux juste ajouter, la convention NSLog et de dénomination est légèrement fausse. statusBarFrameWillChange est appelé avant statusBarFrameChanged afin que la notification de statusBarFrameWillChange soit en fait la valeur OLD et non la nouvelle valeur. Vice versa avec l'autre méthode. – micnguyen