Morgan Cheng
Morgan Cheng

Reputation: 76048

Why assign value to UIView transform property in sequence?

While reading sample code, I found some code about orientation change. The interesting part is that transform property of self.view is assigned with value in sequence. Logically, it seems the first assignment doesn't take any effect since it is overwritten by following assignment.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationPortrait == toInterfaceOrientation) 
    {
        self.view = portraitView;

        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0));

        self.view.bounds = CGRectMake(0, 0, 320, 480);
    } else if (UIInterfaceOrientationLandscapeLeft == toInterfaceOrientation) {
        self.view = landscapeView;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));

        self.view.bounds = CGRectMake(0, 0, 480, 320);
    } else {
        self.view = landscapeView;
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));

        self.view.bounds = CGRectMake(0, 0, 480, 320);
    }
}

The doc says the method willAnimateRotationToInterfaceOrientation is called before orientation animation actually takes place.

So, the assignment to self.view.transform is actually working like pushing value to a stack? or how does Cocoa Touch know that the view should be first set to CGAffineTransfrmIndentity then to another value?

Upvotes: 1

Views: 464

Answers (1)

LordTwaroog
LordTwaroog

Reputation: 1738

Well, identity transform doesn't do anything on its own. So double assignments here are pointless.

BTW: Samples from Apple use only single assignments: GKTank sample

Upvotes: 2

Related Questions