UIInterfaceOrientation一遍又一遍地初始化

时间:2014-04-09 22:18:40

标签: ios initialization uiinterfaceorientation

我已经解决了这个问题很长一段时间,真的需要一些帮助。我有一个教程视图,在启动时显示。我有纵向和横向的图像,我需要做的就是当设备旋转时,选择正确的图像。

我知道我错过了一些简单的事情。但这是我的代码,我将不胜感激。

- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
if (IS_IPAD()) {


if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown){

    self.searchPage = [LTutorialPage page];
    self.searchPage.title = MY_LOCALIZED_STRING(@"search_tutorial_label_1", nil);
    self.searchPage.bgImage = [UIImage imageNamed:@"didactitiel-iPad-port01"];


    self.searchTutr = [[LTutorialView alloc] initWithFrame:rootView.bounds andPages:@[self.searchPage]];

    self.searchTutr.pageControl.hidden = YES;

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    [btn setFrame:CGRectMake((screenWidth-10), 30, 50, 50)];
    [btn setImage:[UIImage imageNamed:@"Close.png"] forState:UIControlStateNormal];

    self.searchTutr.skipButton = btn;
    [self.searchTutr setDelegate:self];
    [self.searchTutr showInView:rootView animateDuration:0.3];
    }

    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){
    self.searchPage = [LTutorialPage page];
    self.searchPage.title = MY_LOCALIZED_STRING(@"search_tutorial_label_1", nil);
    self.searchPage.bgImage = [UIImage imageNamed:@"didactitiel_iPad_land01"];


    self.searchTutr = [[LTutorialView alloc] initWithFrame:rootView.bounds andPages:@[self.searchPage]];

    self.searchTutr.pageControl.hidden = YES;

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

    [btn setFrame:CGRectMake((screenWidth-10), 30, 50, 50)];
    [btn setImage:[UIImage imageNamed:@"Close.png"] forState:UIControlStateNormal];

    self.searchTutr.skipButton = btn;
    [self.searchTutr setDelegate:self];
    [self.searchTutr showInView:rootView animateDuration:0.3];

    }
  }
}

目前正在发生的事情是,每次旋转设备时都会不断添加教程视图。因此,如果设备旋转5次,则会增加5个视图。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您是否尝试过以下操作而不是注册通知?

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;

甚至;

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;