gpt4 book ai didi

iphone - iOS 中的放大和缩小功能

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:12 26 4
gpt4 key购买 nike

我在我的应用程序中编写了这段代码:

- (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);

有时代码运行良好,但有时会显示这样的错误。

Error handler : -[UIView font]: unrecognized selector sent to instance 0xac70780

最佳答案

仔细阅读这篇 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

关于iphone - iOS 中的放大和缩小功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16412581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com