在下面的代码中,我想知道viewTransform
结构是否被初始化,以确定是否旋转我的视图。所以我做viewTransform
了一个指针,而不仅仅是一个常规变量。
这是良好的编程实践,还是有一些潜在的警告?
如果必须,我可以改为声明 aBOOL
来跟踪是否viewTransform
已初始化。
- (void)deviceOrientationDidChange
{
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
CGAffineTransform *viewTransform = NULL;
if (deviceOrientation == UIDeviceOrientationPortrait)
{
*viewTransform = CGAffineTransformIdentity;
}
else if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown)
{
*viewTransform = CGAffineTransformMakeRotation(M_PI * 1.0f);
}
else if (deviceOrientation == UIDeviceOrientationLandscapeLeft)
{
*viewTransform = CGAffineTransformMakeRotation(M_PI * -0.5f);
}
else if (deviceOrientation == UIDeviceOrientationLandscapeRight)
{
*viewTransform = CGAffineTransformMakeRotation(M_PI * 0.5f);
}
if (viewTransform != NULL)
{
for (UIView *view in self.autoRotateViews)
{
[view setTransform:(*viewTransform)];
}
}
}