【发布时间】:2013-01-17 06:53:36
【问题描述】:
我正在使用 MBProgressHud 在初始视图上显示加载指示器,但这不会随设备方向而改变。我的代码是:
splashView = [[UIImageView alloc] initWithFrame:self.window.frame];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
splashView.image = [UIImage imageNamed:@"DefaultPad.png"];
}
else
{
splashView.image = [UIImage imageNamed:@"Default.png"];
}
hud = [[MBProgressHUD alloc]initWithView:splashView];
[splashView addSubview:hud];
hud.userInteractionEnabled=NO;
hud.labelText = @"Loading...";
[hud show:YES];
[self.window addSubview:splashView];
[self performSelector:@selector(Load_FirstView) withObject:nil afterDelay:3];
[self.window makeKeyAndVisible];
我已将 MBProgressHud.m 文件中的行从
- (void)deviceOrientationDidChange:(NSNotification *)notification {
NSLog(@"in device orientation ");
UIView *superview = self.superview;
if (!superview) {
return;
} else if ([superview isKindOfClass:[UIWindow class]]) { // here changes have done
[self setTransformForCurrentOrientation:YES];
} else {
self.bounds = self.superview.bounds;
[self setNeedsDisplay];
}
}
到:
- (void)deviceOrientationDidChange:(NSNotification *)notification {
NSLog(@"in device orientation ");
UIView *superview = self.superview;
if (!superview) {
return;
} else if ([superview isKindOfClass:[UIImageView class]]) {
[self setTransformForCurrentOrientation:YES];
} else {
self.bounds = self.superview.bounds;
[self setNeedsDisplay];
}
}
如何让加载指示器随设备方向旋转?
【问题讨论】:
-
请注意,如果您将图像 DefaultPad.png 重命名为 Default~ipad.png,则可以在第一个代码 sn-p 中省略 if 语句,因为系统会自动识别并在 iPad 上显示它.
标签: iphone objective-c ios device-orientation mbprogresshud