J'ai un exemple très simple UIScrollView
qui ne fait tout simplement pas ce qu'il est censé faire. Je ne sais pas si c'est un bogue avec l'API ou un bogue dans mon code. Fondamentalement, j'ai un UIViewController
avec UIScrollView
comme c'est la vue. Lorsque je l'ajoute au UIWindow
et que je change l'orientation de l'iPad, je me déconnecte de la taille UIScrollView
, qui est incorrecte (?).UIScrollView ne pas obtenir la nouvelle taille sur l'orientation changement
Voici mon UIViewController
mise en œuvre:
@implementation CustomViewController
- (void)loadView {
scrollView = [[[UIScrollView alloc] init] autorelease];
scrollView.delegate = self;
scrollView.backgroundColor = [UIColor redColor];
self.view = scrollView;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
CGSize rect = scrollView.frame.size;
NSLog(@"will rotate w%f h%f", rect.width, rect.height);
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
CGSize rect = scrollView.frame.size;
NSLog(@"will animate rotation w%f h%f", rect.width, rect.height);
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
CGSize rect = scrollView.frame.size;
NSLog(@"did rotate w%f h%f", rect.width, rect.height);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end
Quand je lance le code ci-dessus, je vois les entrées suivantes dans la console:
2010-07-11 11:03:05.214 Untitled2[6682:207] will rotate w768.000000 h1004.000000
2010-07-11 11:03:05.214 Untitled2[6682:207] will animate rotation w748.000000 h1024.000000
2010-07-11 11:03:05.619 Untitled2[6682:207] did rotate w748.000000 h1024.000000
2010-07-11 11:03:07.951 Untitled2[6682:207] will rotate w748.000000 h1024.000000
2010-07-11 11:03:07.958 Untitled2[6682:207] will animate rotation w768.000000 h1004.000000
2010-07-11 11:03:08.367 Untitled2[6682:207] did rotate w768.000000 h1004.000000
Comme vous pouvez le voir, les changements d'orientation ne redimensionne la UIScrollView
, mais seulement pour permettre la nouvelle barre d'état. Je m'attendrais à ce que la largeur et la hauteur changent radicalement, car le UIScrollView
est plus large que haut et vice versa.
Existe-t-il un moyen d'obtenir le UIScrollView
pour signaler sa taille réelle?
Cela ne fonctionne pas. J'intercepte un changement, puis j'utilise NSStringFromRect (self.bounds) et il imprime les limites "juste avant de changer". Mais l'orientation currentDevice renvoie la valeur correcte. Au moins, celui-ci revient constamment la même chose correctement, mais l'homme ... ce problème ne devrait pas prendre autant de temps. A partir des docs, alors que les bornes sont les non-dérivées, n'est-ce pas toujours 0,0, même largeur de cadre, même hauteur de cadre? –
L'origine des limites est toujours 0,0 par défaut sauf si vous modifiez la partie de vue que vous souhaitez afficher. Ce n'est que la moitié de l'histoire, un CGRect contient aussi un membre de taille et c'est ce qui change habituellement lorsque vous redimensionnez, réorienter une vue. Les fonctions "volonté" ci-dessus vous donnent les "valeurs avant", les fonctions "faites" vous donnent les "valeurs après". –