1

次のコードを使用して、画像ビューを回転および変換しています。

myImageView.transform = CGAffineTransformMakeRotation(45); // rotation

CGRect frame = myImageView.frame;
frame.origin.x = x_position;
frame.origin.y = y_position;
myImageView.frame = frame; // transformation
4

2 に答える 2

2

tl;dr:frameあなたが非同一性を持っているとき、それは偽物ですtransform. 代わりに を変更しcenterます。


ドキュメントから:

警告プロパティが恒等変換でない場合、transformこのプロパティの値は未定義であるため、無視する必要があります。

最初の行で変換を設定し、その後にフレームを読み取る場合、実際に返されるものは未定義です。

// Setting a non-identity transform (1)
myImageView.transform = CGAffineTransformMakeRotation(45); 

CGRect frame = myImageView.frame; // At this point the frame is undefined (2)
// You are modifying something which is undefined from now on ...

また、フレームが未定義であるため、フレームを読み取らないだけでなく、設定しないでください。

transformプロパティに非恒等変換が含まれている場合、frame プロパティの値は未定義であり、変更しないでください。

その問題の解決策は、ドキュメントの次の文にあります

その場合、center プロパティを使用してビューの位置を変更し、代わりに bounds プロパティを使用してサイズを調整できます。

位置を変更するだけなので、フレームに触れずに、代わりcenterに画像ビューを読み取って新しい値に設定することをお勧めします。はcenter、フレームと同じようにトランスフォームの影響を受けません。

CGPoint center = myImageView.center; 
center.x = x_center_position; // Note that the `center` is not the same as the frame origin.
center.y = y_center_position; // Note that the `center` is not the same as the frame origin.
myImageView.center = center; 
于 2013-03-02T08:37:42.180 に答える
0

ImageView の自動サイズ変更マスクを削除してみてください

imageView.autoresizingMask = UIViewAutoresizingNone;

これで問題が解決する場合があります

于 2013-03-02T08:35:27.680 に答える