سؤال

لقد كنت أبحث كثيرًا عن هذا ، ولا يمكنني العثور على أي شيء لمساعدتي.

لديّ UiviewController الموجود في UiviewController آخر. عندما يدور الوالد UiviewController ، قل من الصورة إلى المناظر الطبيعية ، أريد أن أجعله يبدو كما لو أن الطفل لم يدور. ذلك بالقول. أريد أن يكون للطفل نفس التوجه إلى السماء بغض النظر عن اتجاه الوالد. إذا كان يحتوي على Uibultton في وضع مستقيم في الصورة ، فأنا أريد أن يكون الجانب الأيمن من الزر "Up" في UiInterfaceorientationlandscapeleft.

هل هذا ممكن؟ حاليا ، أنا أفعل أشياء جسيمة مثل هذا:

-(void) rotate:(UIInterfaceOrientation)fromOrientation: toOr:(UIInterfaceOrientation)toOrientation
{
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeRight))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeLeft))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeRight)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
       || ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationPortrait)))
    {

    }
    if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationLandscapeRight))
       || ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
    {

    }   
}

الذي يبدو وكأنه مضيعة جيدة تماما للرمز. علاوة على ذلك ، كنت أخطط لاستخدام cgaffinetransform (مثل المذكورة هنا: http://www.crystalminds.nl/؟p=1102) لكنني في حيرة من أمري بشأن ما إذا كان ينبغي عليّ تغيير أبعاد العرض لمطابقة ما ستكون عليه بعد الدوران.

الكابوس الكبير هنا هو أنه يتعين عليك تتبع متغير "اتجاه" عالمي. إذا لم تقم بذلك ، يتم فقدان الوهم ويتم تدوير ViewController إلى أي شيء.

يمكنني حقًا استخدام بعض المساعدة في هذا ، شكرًا!

هل كانت مفيدة؟

المحلول

أفضل شيء يمكنك القيام به هو تغيير إطارات إطارات UR Subview وفقًا لتوجهات واجهة UR. يمكنك أن تفعل ذلك مثل:

 #pragma mark -
 #pragma mark InterfaceOrientationMethods

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        //self.view = portraitView;
        [self changeTheViewToPortrait:YES andDuration:duration];

    }
    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        //self.view = landscapeView;
        [self changeTheViewToPortrait:NO andDuration:duration];
    }
}

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];

    if(portrait){
        //change the view and subview frames for the portrait view
    }
    else{   
        //change the view and subview  frames for the landscape view
    }

    [UIView commitAnimations];
}

أتمنى أن يساعدك هذا.

نصائح أخرى

أدركت شيئًا .. دعنا نقول أن مشروعنا لديه طبقة متعددة من ViewController (كما هو الحال في إذا قمت بإضافة عرض فرعي لوحدة التحكم الأخرى إلى وحدة تحكم العرض الخاصة بك)

willrotatetointerfaceorientation: لن يتم استدعاء طريقة المدة للطبقة الثانية من ViewController ...

إذن ما فعلته هو ، بعد أن قمت بتهيئة وحدة التحكم في طريقة عرض الطبقة الثانية من أعلى الطبقة الخاصة بي ، ثم عندما يتم استدعاء طريقة المدة على الطبقة العليا ، سأتصل بـ willrotatetointerfaceorient.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top