views:

350

answers:

2

Hi.

How do I rotate the ImageView ... i'm trying to use landscape mode, and have a problem with accelerometer moving the image ... Because when I work in portrait mode the x of accelerometer is the same as the x of the image ... But when I work landscape, the x of accelerometer is the y of the image, because the ImageView autorotates with the parent View. When I rotate the image with CGAffineTransformMakeRotation(M_PI/2), it rotates only the image in it's ImageView... and the x,y sides stays untouched ... Is there any way to make own class which will extend UIImageView where I will swap the x,y sides of a UIImageView ? Or is there some way to rotate the UIImageView, and not only the image in it?

A: 

float degree = atan2(accelX, accelY) * 180 / 3.14159;

where accelX and accelY are the values from the accelerometer, use the degree and rotate the ImageView.

Chandan Shetty SP
can u please post some example ?Don't know if i understand it ... :(
Kuko
dont know if you understand me correctly ... i want to rotate it exactly by 90 degree, but NOT only the image in the ImageView, but want to somehow swap x and y of the UIImageView ...
Kuko
A: 

Try to convert points depending on orientation...

if( orientation == LANDSCAPE ) {

CGPoint temp;

temp = [touch locationInView:self];

touchPoint.x = temp.y;

touchPoint.y = 320 - temp.x;

}

The above code convert points from portrait to landscape...

Chandan Shetty SP