旋转后重新绘制按钮



我在UIView上动态绘制了一些按钮。我根据一些数学计算来决定帧,我想在设备旋转时重新绘制屏幕。我注册了用于轮换通知的代码,didRotate:委托方法工作正常。旋转时如何重新绘制屏幕?更多解释:如果旋转模式为"纵向",我会画两列按钮,如果旋转到"横向",我想画四列。。按钮数据是动态的,来自我的HTTP服务器(按钮数等)

我建议您使用"willAnimateRotationToInterfaceOrientation"方法,该方法允许您在旋转设备时控制视图。这是一些简单的代码,它给了你一个让事情发挥作用的想法:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
// if you are in portrait mode
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    [yourOutletName setFrame:CGRectMake(255, 6, 25, 25)];
} 
// if you are in landscape mode
else
{
    [yourOutletName setFrame:CGRectMake(415, 6, 25, 25)];
}
}

最新更新