问题
I can't figure out why this isn't working. I'm writing a game that involves scrolling rows/columns of blocks around the screen. I have my orientation limited strictly to Portrait, but it doesn't behave as so.
When I call the method below, it is handed the velocity from the pan. Using logs I was able to see that holding my device upside-down and panning around acts as if my orientation supports Portrait. How can I -completely- turn off anything but Portrait?
Here's some code to help explain what I want to do, and to hopefully justify my sanity.
bool horizontalPan = (fabs(velocity.x) >= (fabs(velocity.y)));
if (horizontalPan)
{
if (fabs(velocity.x) > MAX_VELOCITY)
{
if (velocity.x > 0)
velocity = CGPointMake(MAX_VELOCITY, 0);
else
velocity = CGPointMake(-MAX_VELOCITY, 0);
}
else
{
velocity = CGPointMake(velocity.x, 0);
}
velocity = ccpMult(velocity, PAN_SENSITIVITY);
[self panRow:velocity object:object];
}
else
{
if (fabs(velocity.y) > MAX_VELOCITY)
{
if (velocity.y > 0)
velocity = CGPointMake(0, MAX_VELOCITY);
else
velocity = CGPointMake(0, -MAX_VELOCITY);
}
else
{
velocity = CGPointMake(0, velocity.y);
}
velocity = ccpMult(velocity, PAN_SENSITIVITY);
[self panColumn:velocity object:object];
}
}
回答1:
How did you 'strictly limit to portrait' did you use
-(BOOL)shouldAutorotate{
return NO;
}
来源:https://stackoverflow.com/questions/14668685/improper-iphone-orientation