【问题标题】:Toolbar and Navigationbar bad Animation工具栏和导航栏不良动画
【发布时间】:2011-08-24 18:02:55
【问题描述】:
我想做的是在横向模式下旋转并将工具栏和导航栏留在(工具栏垂直于右侧,导航栏垂直于左侧),但仅旋转视图和图标在工具栏和导航栏上..
到目前为止我所做的是使用 willAnimateSecondHalfofRotation。当进入横向模式时,位置是我想要的,但我可以看到旋转的过渡,它看起来很糟糕。我想做的是像 iPhone 的相机一样工具栏的图标正在旋转...
你能帮帮我吗?
先谢谢了。
洛尔
【问题讨论】:
标签:
iphone
objective-c
ios
【解决方案1】:
-
禁用自动旋转:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-
注册 UIDeviceOrientationDidChange 通知:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
-
响应设备方向变化:
- (void)orientationChanged:(NSNotification *)notification {
// Adjust views according to [[UIDevice currentDevice] orientation];
}
-
别忘了注销
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self];