我有一個UIButton,我以編程方式實現,因爲它僅在旋轉設備時需要。UIButton在返回到VC時沒有響應removeFromSuperView
當我旋轉時,按鈕需要消失,當我走到風景時出現。
只要我留在相同的ViewController我沒有問題。無論如何,我可以旋轉設備,按鈕出現並按預期消失。 該應用程序是基於TabController的應用程序,當我轉到另一個選項卡時,會發生相同的行爲。
這就是問題 當我回到原始視圖時,按鈕出現,但從未消失。它幾乎就像removeFromSuperView
沒有被調用,但即使是這樣,按鈕也不會被刪除。
任何想法爲什麼這樣?
-(void)autoRotationDetection
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
}
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
/* start special animation */
[_menuButton removeFromSuperview];
break;
case UIDeviceOrientationPortraitUpsideDown:
/* start special animation */
break;
default:
break;
};
}
然後我打電話
-(void)viewWillAppear:(BOOL)animated
{
[self autoRotationDetection];
}
對不起應該補充說。
你應該顯示你調用removeFromSuperview的方法。 – rdelmar 2013-03-27 20:55:10
我添加了代碼:-)對不起,我忘了:-) – 2013-03-27 21:06:45
1.驗證你的方法正在調用,2.驗證'_menuButton'不是'nil'並指向正確的菜單按鈕。 3.確保你在主線程中(我認爲它應該是)。 – Joe 2013-03-27 21:06:46