UIWebView에서 확대 / 축소 / 핀치 활성화
pdf 파일이있는 UIWebView가 있습니다. 잘 작동합니다. 그러나 pdf 파일에서 확대 / 축소를 활성화하려면 어떻게해야합니까?
"페이지에 맞게 크기 조정"을 선택했는지 확인하십시오.
webView.scalesPageToFit=YES;
프로그래밍 방식으로 사용할 수 있습니다.
xib에서 사용하는 경우 click the check box "Scaling" scales Page to fit
UIWebView의 확대 / 축소를위한이 논리는 UIScrollView에 UIWebView를 추가 할 필요가 없습니다.
유일한 문제 webView.scalesPageToFit = YES;
는 글꼴 크기의 초기 내용이 변경되지만 다른 옵션을 찾았다는 것입니다.
추가 <UIWebViewDelegate, UIScrollViewDelegate>
사용자에 .H 파일
당신의 창조 UIWebView.
self.mWebview = [[UIWebView alloc] init];
self.mWebview.delegate = self; /// set delegate method of UIWebView
self.mWebview.frame = CGRectMake(0, 35, self.view.bounds.size.width, self.view.bounds.size.height - 80); // set frame whatever you want..
[self.mWebview setOpaque:NO];
self.mWebview.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.mWebview];
HTML 파일 / 콘텐츠를로드합니다.
NSString* htmlString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"File Name"ofType:@"html"] encoding:NSUTF8StringEncoding error:nil];
[self.mWebview loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
#pragma mark -
#pragma mark - Webview Delegate Methods
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
webView.scrollView.delegate = self; // set delegate method of UISrollView
webView.scrollView.maximumZoomScale = 20; // set as you want.
webView.scrollView.minimumZoomScale = 1; // set as you want.
//// Below two line is for iOS 6, If your app only supported iOS 7 then no need to write this.
webView.scrollView.zoomScale = 2;
webView.scrollView.zoomScale = 1;
}
#pragma mark -
#pragma mark - UIScrollView Delegate Methods
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
self.mWebview.scrollView.maximumZoomScale = 20; // set similar to previous.
}
참고 : Mac OS X-10.9.3에서 Xcode 5.1.1 및 iOS 버전 6.1 이상을 테스트해야했습니다.
이 정보가 도움이되기를 바랍니다. :)
나는이 질문이 꽤 오래되었다는 것을 알고 있지만, 스토리 보드를 사용하고 여기에서 시각적 인 대답을 선호하는 모든 사람들에게는 그것이 있습니다. WebView의 속성 검사기에서이 확인란을 선택하면됩니다.
프로그래밍 방식으로 수행하려면
webView.scalesPageToFit = true;
스토리 보드를 사용하는 경우 "크기 조정"확인란을 선택해야 페이지 크기에 맞게 조정됩니다.
UIWebView에서 작동하도록 핀치 및 확대 / 축소에 대해 scalesPageToFit = YES를 설정해야합니다. 그것은 나를 위해 일합니다.
참고 URL : https://stackoverflow.com/questions/7134576/enable-zooming-pinch-on-uiwebview
'Programing' 카테고리의 다른 글
HTML 페이지에서 원을 그리는 방법? (0) | 2020.08.12 |
---|---|
두 목록 간의 공통 요소 비교 (0) | 2020.08.12 |
Sublime-특정 값을 포함하는 모든 줄 삭제 (0) | 2020.08.12 |
배열을 정렬하는 TypeScript (0) | 2020.08.12 |
데이터베이스 디자인에 외래 키가 정말로 필요합니까? (0) | 2020.08.12 |