放大UIWebView有很多問題,但我找不到我的答案。UIWebView不縮放超過x2
我已經有WebView的ViewController。我在這個WebView中加載了一個SVG文件,並且我想通過點擊它來放大。下面是代碼:
@interface ViewController : UIViewController <UIGestureRecognizerDelegate>
{
IBOutlet MyWebView *webView;
UITapGestureRecognizer *doubleTapRecognizer;
CGFloat k;
}
...
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"map" withExtension:@"svg"]]];
webView.scalesPageToFit = YES;
webView.scrollView.maximumZoomScale = 512;
webView.scrollView.minimumZoomScale = 0.1;
doubleTapRecognizer.numberOfTapsRequired = 2;
doubleTapRecognizer.numberOfTouchesRequired = 1;
doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTapRecognizer.delegate = self;
doubleTapRecognizer.enabled = YES;
[webView addGestureRecognizer:doubleTapRecognizer];
k = 1;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
- (void)doubleTap:(UITapGestureRecognizer*)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
k = 10;
// No one does not work correctly
[webView.scrollView setZoomScale:k animated:YES];
// [webView setContentScaleFactor:k];
// [webView.scrollView setContentScaleFactor:k];
// webView.scrollView.zoomScale = k;
// [webView.scrollView zoomToRect:CGRectMake(webView.bounds.origin.x, webView.bounds.origin.y, webView.bounds.size.width/k, webView.bounds.size.height/k) animated:YES];
}
}
現在的WebView是由自來水放大,但只有X2並沒有更多的。什麼是錯的,我怎麼能放大x10?
我覺得你打電話給doubleTapRecognizer.numberOfTouchesRequired = 1;然後立即重新初始化doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:...可能會有一些副作用保留第一個設置,但它聞起來像臭蟲! –
是的,這當然是一個錯誤:)如果你已經注意到,在-viewDidLoad中分配手勢識別器(或任何其他對象)是一個非常糟糕的做法,這可能會導致內存泄漏。我在半年前太蠢了 – medvedNick
現在我想我們正在ARC燈下曬太陽,我們可以繼續在各種「愚蠢」的地方分配東西。這就像在C#工作:-) –