2

私は自分のアプリでこのコードを書いています:

- (IBAction)ZoomInFunction{
@try{
    UITextField *test  = (UITextField *)[self.view viewWithTag:indexNews];
    NSLog(@"INDEX NEWS : %d", indexNews);

    UIFont *font = test.font;
    if(test.font == [font fontWithSize:22])
        test.font = [font fontWithSize:22];
    else
        test.font = [font fontWithSize:font.pointSize+2];
}@catch (NSException *err) {
    NSLog(@"Error handler : %@", err);
}

}

- (IBAction)ZoomOutFunction{
@try {
    UITextField *test  = (UITextField *)[self.view viewWithTag:indexNews];

    UIFont *font = test.font;
    if(test.font == [font fontWithSize:14])
        test.font = [font fontWithSize:14];
    else
        test.font = [font fontWithSize:font.pointSize-2];
}@catch (NSException *err) {
    NSLog(@"Error handler : %@", err);

}

コードが正常に実行される場合もありますが、エラーが次のように表示される場合もあります。

エラー ハンドラー: -[UIView フォント]: 認識されないセレクターがインスタンス 0xac70780 に送信されました

4

3 に答える 3

1

UITextView ではスケーリングが可能です。テキストの入力中に動的に拡大し、ユーザーが画面をつまむとスケーリングする UITextView (同様の動作が TinyPost に見られます)。

これをviewDidLoadに適用

    UITextView *test  = (UITextView *)[self.view viewWithTag:indexNews];

    UIPinchGestureRecognizer *gestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleTextView:)];

    [test addGestureRecognizer:gestureRecognizer];

このようにUITextViewにズームインとズームアウトを適用します

- (void)scaleTextView:(UIPinchGestureRecognizer *)pinchGestRecognizer{

     CGFloat scale = pinchGestRecognizer.scale;

    createTextView.font = [UIFont fontWithName:createTextView.font.fontName size:createTextView.font.pointSize*scale];

    [self textViewDidChange:createTextView];       
}

- (void)textViewDidChange:(UITextView *)textView{

     CGSize textSize = textView.contentSize;

     textView.frame = CGRectMake(CGRectGetMinX(textView.frame), CGRectGetMinY(textView.frame), textSize.width, textSize.height); //update the size of the textView  
 }

うまくいくことを願っています。

于 2013-05-07T12:19:33.723 に答える
1

この Apple の記事を注意深く読んで、IOS のズームインおよびズームアウト機能を理解してください。

実際のコードは次のとおりです。

       UITextView *textView = [UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
    UIPinchGestureRecognizer *gestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(changeFontSize:)];
    [textView addGestureRecognizer:gestureRecognizer];

- (void)changeFontSize:(UIPinchGestureRecognizer *)gestureRecognizer 
 {
    UITextView *textView = (UITextView *)gestureRecognizer.view;
    float yourFontSize = gestureRecognizer.scale * FONT_SIZE;
    textView.font = [UIFont systemFontOfSize:yourFontSize];
 }

http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/UIScrollView_pg/ZoomZoom/ZoomZoom.html

于 2013-05-07T06:37:58.897 に答える
0

私はそれを適用し、適切な解決策を得ました。これは、次のコード行によるものです

UITextField *test  = (UITextField *)[self.view viewWithTag:indexNews];

viewWithTag:indexNews を介して self.view から UITextView を取得すると、この indexNews タグの値が既に他の UIView に割り当てられているため、このコード行は UITextField ではなく UIView を取得します。そのため、UIView 経由で Font メソッドを呼び出すことができないため、エラーが返されます。私はそれに対するより良い解決策を持っています

.h ファイルで、UITextView のアウトレットを実装します。

@property (weak, nonatomic) IBOutlet UITextView *fontTextView;

.m ファイル内

@synthesize fontTextView;

- (IBAction)ZoomInFunction{
    @try{

        UIFont *font = fontTextView.font;
        if(fontTextView.font == [font fontWithSize:22])
            fontTextView.font = [font fontWithSize:22];
        else
            fontTextView.font = [font fontWithSize:font.pointSize+2];
    }@catch (NSException *err) {
        NSLog(@"Error handler : %@", err);
    }

}

- (IBAction)ZoomOutFunction{
    @try {

        UIFont *font = fontTextView.font;
        if(fontTextView.font == [font fontWithSize:14])
            fontTextView.font = [font fontWithSize:14];
        else
            fontTextView.font = [font fontWithSize:font.pointSize-2];
    }@catch (NSException *err) {
        NSLog(@"Error handler : %@", err);

    }
}

あなたのコードでうまくいくことを願っています。ありがとう

于 2013-05-08T05:52:05.567 に答える