ما هي بعض الأسباب المحتملة ل Uiview نادرا ما لا يتم تدويرها عند إعادة النظر؟

StackOverflow https://stackoverflow.com/questions/1236728

سؤال

أضع هذا الرمز في كل من رأيي:

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

    if (orientation == UIInterfaceOrientationLandscapeRight) {
        CGAffineTransform transform = self.view.transform;

        // Use the status bar frame to determine the center point of the window's content area.
        //CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
        //CGRect bounds = CGRectMake(0, 0, statusBarFrame.size.height, statusBarFrame.origin.x);
        CGPoint center = CGPointMake(320/2, 480/2);

        // Set the center point of the view to the center point of the window's content area.
        self.view.center = center;

        // Rotate the view 90 degrees around its new center point.
        transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
        self.view.transform = transform;
    }   

ولدي أيضا:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations

    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

أستطيع أن أرى أن الرموز تعمل بشكل صحيح كما ينبغي، ولكن مرة واحدة في حين، هناك مناسبة نادرة فشلت وحدة تحكم الرؤية الرئيسية في تدوير وضع المناظر الطبيعية بعد أن أضع عرضها ليكون الرأي الرئيسي. فرصة حدوثها نادرة جدا، ولكن هذا هو مزعج لي. علاوة على ذلك، أستطيع أن أرى أنه يحدث في كثير من الأحيان على iPhone. على المحاكاة، أتذكر أنه لا يحدث أبدا. هل تعرف ما هي الأسباب المحتملة لهذا؟ شكرا لكم مقدما.

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

المحلول

لقد وجدت سبب برنامج iPhone الخاص بي.

واحدة من الأسباب المحتملة هي الذاكرة. سيتم استدعاء هذه الطريقة أدناه عندما يكون النظام منخفضا في الذاكرة:

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

Uiview "غير مرئي" يتم تفريغها عند استدعاء هذه الطريقة. عندما تكون على وشك رؤية هذا الرأي مرة أخرى، إعادة تحميل الجهاز، ولكن ربما لأنك تقوم بتعيين المعلمات (للدوران، وما إلى ذلك) في مكان لن يتم استدعاؤه عند إعادة تحميله. يمكنك استخدام:

- (void)viewDidLoad {

    UIApplication* application = [UIApplication sharedApplication];
    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation([MyMath radd:90]);
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, -80, 83);

    [self.view setTransform: landscapeTransform];
    [super viewDidLoad];
}

يحدث في الجهاز بسبب نتحدث عن الذاكرة الحقيقية على الجهاز الحقيقي. يمكنك استخدام "الأجهزة> محاكاة تحذير الذاكرة" عند استخدام Simulator.

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