3
我想增加和縮小字體大小與捏和進出。但是下面的手勢非常緩慢。如何優化它作爲UIWebView工作。如何優化UIPinchGestureRecognizer增加和減小字體大小?
- (void)viewDidLoad {
textView.text = @"fdsakllllllllllllllllllllllllllllllfadsjksadfjkjkasdfjkjksfjkdajkasfdjkjhasdfhhjasdfhadfjkskasfdjkjkahsfdjkasdfjkjkasfdkjfsdahkafsdjkadjksfjkajksdfjkasdfkafjksdajksdffdsakllllllllllllllllllllllllllllllfadsjksadfjkjkasdfjkjksfjkdajkasfdjkjhasdfhhjasdfhadfjkskasfdjkjkahsfdjkasdfjkjkasfdkjfsdahkafsdjkadjksfjkajksdfjkasdfkafjksdajksdffdsakllllllllllllllllllllllllllllllfadsjksadfjkjkasdfjkjksfjkdajkasfdjkjhasdfhhjasdfhadfjkskasfdjkjkahsfdjkasdfjkjkasfdkjfsdahkafsdjkadjksfjkajksdfjkasdfkafjksdajksdffdsakllllllllllllllllllllllllllllllfadsjksadfjkjkasdfjkjksfjkdajkasfdjkjhasdfhhjasdfhadfjkskasfdjkjkahsfdjkasdfjkjkasfdkjfsdahkafsdjkadjksfjkajksdfjkasdfkafjksdajksfsdjkadjksfjkajksdfjkasdfkafjksdajksdffdsakllllllllllllllllllllllllllllllfadsjksadfjkjkasdfjkjksfjkdajkasfdjkjhasdfhhjasdfhadfjkskasfdjkjkahsfdjkasdfjkjkasfdkjfsdahkafsdjkadjksfjkajksdfjkasdfkafjksdajksdffdsakllllllllllllllllllllllllllllllfadsjksadfjkjkasdfjkjksfjkdajkasfdjkjhasdfhhjasdfhadfjkskasfdjkjkahsfdjkasdfjkjkasfdkjfsdahkafsdjkadjksfjkajksdfjkasdfkafjksdajksdffdsakllllllllllllllllllllllllllllllfadsjksadfjkjkasdfjkjksfjkdajkasfdjkjhasdfhhjasdfhadfjkskasfdjkjkahsfdjkasdfjkjkasfdkjfsdahkafsdjkadjksfjkajksdfjkasdfkafjksdajksdf";
UIPinchGestureRecognizer *pinchGesture =
[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
pinchGesture.delegate = self;
/*textView.maximumZoomScale = 3;
textView.minimumZoomScale = .5;
*/
[textViewHadith addGestureRecognizer:pinchGesture];
[pinchGesture release];
// [textViewHadith setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"blackback ground.png"]]];
}
- (IBAction)handlePinchGesture:(UIGestureRecognizer *)sender {
// static CGRect initialBounds;
static int fontSize = 20;
// UIView *_view = sender.view;
if (sender.state == UIGestureRecognizerStateBegan)
{
// initialBounds = _view.bounds;
}
CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
// NSLog(@"factor = %f",factor);
if(factor > 1.0)
{
fontSize +=1;
}
else
{
fontSize -= 1;
}
// NSLog(@"font = %d",fontSize);
if (fontSize >50) {
fontSize =50; return;
}
if (fontSize <5) {
fontSize = 5; return;
}
[textView setFont:[UIFont fontWithName:@"Helvetica" size:fontSize]];
// CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
// _view.bounds = CGRectApplyAffineTransform(initialBounds, zt);
return;
}
-(void) viewDidUnload
{
textView = nil;
}
@end