それ自体がビューであるトラックバーを使用してアプリを実装しており、(バーに関連付けられている変数の)最小値と最大値を表示する必要があるため、左上と右上に2つのラベルを追加しました。スライダーが有効になっていない場合は、次のように考えてください。
ピンチジェスチャでこのビューを縮小または拡大できるようにしたいと思います。以下のコードは正常に機能します。
-(void) handlePinch:(UIPinchGestureRecognizer *)gr
{
//Shrinking
if(gr.scale < 1)
{
//Get screen width
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
//If the view's would be size is smaller than half the screen's size then don't do anything
//Otherwise shrink the view
if(self.frame.size.width * gr.scale >= screenWidth / 2)
{
//Only scale on x axis, y axes stays the same
self.transform = CGAffineTransformScale(self.transform, gr.scale, 1);
}
}
//Magnifying
else if (gr.scale > 1)
{
//Only scale on x axis, y axes stays the same
self.transform = CGAffineTransformScale(self.transform, gr.scale, 1);
}
//Set scale amount back to 1
gr.scale = 1;
}
問題は、ビューが縮小されると、左上と右上のラベルも縮小され、フォントサイズが小さくなることです。ビューを水平方向にのみ拡大縮小するので、これは奇妙に見えます。ラベルのサイズを一定に設定し、ビュー内の他のすべてを縮小したいと思います。
縮小した後、元のラベルのサイズで新しいフレーム長方形を割り当てようとしましたが、機能しませんでした。ヒントはありますか?
編集:minimumFontSizeプロパティの設定も機能しませんでした(私はまだios 5 sdkを使用しているため、minimumScaleFactorを試しません)