I want to zooming in out in WebView.I am newer in iOS.Please Help me.Some one say it is default property of WebView.I am testing in iOS8 . It does not work for me.
self.myWebView= [[UIWebView alloc] init];
[self.myWebView setScalesPageToFit:YES];
[self.myWebView setDelegate:self];
[self.myWebView.scrollView setDelegate:self];
[self.myWebView setDataDetectorTypes:UIDataDetectorTypeNone];
[self.myWebView.scrollView setBounces:NO];
[self.myWebView.scrollView setShowsHorizontalScrollIndicator:NO];
[self.myWebView.scrollView setShowsVerticalScrollIndicator:NO];
[myScrollView addSubview:self.myWebView];
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
self.myWebView.scrollView.delegate = self;
self.myWebView.scrollView.maximumZoomScale = 20; // set as you want.
self.myWebView.scrollView.minimumZoomScale = 1; // set as you want.
}
(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
self.myWebView.scrollView.maximumZoomScale = 20;
}
if u are not use viewForZoomingInScrollView they work automatically. if you are use viewForZoomingInScrollView
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
if (scrollView ==myWebView.scrollView){
return self.myWebView;
}
else
{
return nil;
}
}
Related
I want to disable Zoom in zoom out in webview od ios 11. i use xcode 9 i used
In my AppDelegate.m
1:-
- (void)webViewDidFinishLoad:(UIWebView *)webView {
webView.scalesPageToFit = NO;
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *) scrollView
{
return nil;
}
2:-
- (void)webViewDidFinishLoad:(UIWebView *)webView {
webView.scrollView.maximumZoomScale = 1.0;
webView.scrollView.minimumZoomScale = 1.0;
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *) scrollView
{
return nil;
}
3:-
- (void)hijackWebViewScrollViewDelegate:(UIWebView *)webView {
UIScrollView *scrollView = (UIScrollView *)[webView.subviews objectAtIndex:0];
scrollView.delegate = self;//xcode shows error in this is Assigning to 'id<UIScrollViewDelegate> _Nullable' from incompatible type 'AppDelegate *const __strong'**
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return nil;
}
4:-I use this one in my AppDelegate.m and apply scrollViewDelegate in h no error but required is not achieved.
#implementation AppDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView {
webView.scrollView.delegate = self;
webView.scrollView.maximumZoomScale = 1.0;
webView.scrollView.minimumZoomScale = 1.0;
webView.scalesPageToFit = NO;
webView.multipleTouchEnabled=NO;
}
- (UIView *) viewForZoomingInScrollView:(UIScrollView *) scrollView
{
return nil;
}
It's work for me. I hope work for you!!
class ViewController: UIViewController, UIScrollViewDelegate{
//MARK: UIScrollView Delegate Methods
func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?){
scrollView.pinchGestureRecognizer?.isEnabled = false
//For Avoid Zoom in Webview's content we are disable pinchGestureRecognizer
}
}
//Objective-C
//Use below code for Objective-C
-(void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{
[[scrollView pinchGestureRecognizer] setEnabled:false];
}
Note : Don't forgot to add UIScrollviewDelegate
I have this code:
#pragma mark - UIScrollViewDelegate Methods
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.lastOffsetY = scrollView.contentOffset.y;
}
- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
if (self.canAnimateBars)
[self animeteBars:scrollView];
}
- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if(self.canAnimateBars)
[self animeteBars:scrollView];
}
-(void)animeteBars:(UIScrollView *)scrollView {
bool hide = (scrollView.contentOffset.y > self.lastOffsetY);
[self.view layoutIfNeeded];
if (hide)
self.quickLinkToolBarBotom.constant = -44.0;
else
self.quickLinkToolBarBotom.constant = 0.0;
[[self navigationController] setNavigationBarHidden:hide animated:YES];
}
#pragma mark - UIWebViewDelegate Methods
- (void)webViewDidFinishLoad:(UIWebView *)webView {
self.canAnimateBars = YES;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(#"Error: %#", error.localizedDescription);
}
It is working ok, but Would like to archive the same behaviour of the Safari animation.
I have tried this library AMScrollingNavbar but I can't make it work with the Tool Bar.
How can I make the calculations to move the bars while I'm scrolling the Web view like in Safari.
Thanks for the help.
You can use this code. i think this code used for you.
-(void)animeteBars:(UIScrollView *)scrollView {
bool hide = (scrollView.contentOffset.y > self.lastOffsetY);
[self.view layoutIfNeeded];
CGFloat duration = 0.3;
if (hide)
{
[UIView animateWithDuration:duration animations:^{
self.quickLinkToolBarBotom.constant = -44.0;
} completion:nil];
}
else
{
[UIView animateWithDuration:duration animations:^{
self.quickLinkToolBarBotom.constant = 0.0;
} completion:nil];
}
[[self navigationController] setNavigationBarHidden:hide animated:YES];
}
In my application having gallery functionality.For Scrolling image i used REPagedScrollView and i want to image zoom on pinch using 2 finger and also want zoom on double tap but i unable to to zoom image on double tap
please resolved my problem.
I tried by below code :
.h file
#interface ViewPhotoVC : UIViewController<UIScrollViewDelegate,UIGestureRecognizerDelegate>
{
REPagedScrollView *scrollView;
UIScrollView *image_scroll;
int current_page;
BOOL is_FullScreen;
}
#property (strong,nonatomic) IBOutlet UIView *slider_view;
.m file
-(void)video_image_Gallery
{
scrollView = [[REPagedScrollView alloc] initWithFrame:self.slider_view.bounds];
scrollView.delegate=self;
// scrollView.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
// scrollView.pageControl.currentPageIndicatorTintColor = [UIColor grayColor];
current_page=0;
for(int i=0;i<[self.PhotoImgArr count];i++){
self.image_view = [[AsyncImageView alloc] initWithFrame:CGRectMake(0,0, self.slider_view.frame.size.width, self.slider_view.frame.size.height)];
// scrollView.frame=CGRectMake(0, 0, screenwidth, screenheight);
image_scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,screenwidth,screenheight)];
self.image_view.backgroundColor=[UIColor clearColor];
self.image_view.contentMode = UIViewContentModeScaleAspectFit;
self.image_view.clipsToBounds = true;
self.image_view.userInteractionEnabled = YES;
self.image_view.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
self.image_view.image = [UIImage imageNamed:#"no_image1.png"];
self.image_view.imageURL =[NSURL URLWithString:[self.PhotoImgArr objectAtIndex:i]];
self.image_view.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:246.0/255.0 blue:241.0/255.0 alpha:1];
[image_scroll setDelegate:self];
[image_scroll setShowsHorizontalScrollIndicator:NO];
[image_scroll setShowsVerticalScrollIndicator:NO];
[image_scroll setMaximumZoomScale:8.0];
image_scroll.tag=i+1;
self.PlayVideoBtn.tag=i+1;
self.image_view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
image_scroll.contentSize = CGSizeMake(self.image_view.bounds.size.width-500, self.image_view.bounds.size.height-300);
image_scroll.decelerationRate = UIScrollViewDecelerationRateFast;
// [image_scroll setMinimumZoomScale:[image_scroll frame].size.width / [self.image_view frame].size.width];
[image_scroll setZoomScale:[image_scroll minimumZoomScale]];
[image_scroll addSubview:self.image_view];
[image_scroll addSubview:self.PlayVideoBtn];
[image_scroll addSubview:self.videoImg];
scrollView.tag=0;
// self.PlayVideoBtn.tag=0;
[scrollView addPage:image_scroll];
}
[self.slider_view addSubview:scrollView];
self.index_lbl.text = [NSString stringWithFormat:#"%d of %lu",(int)self.selected_index+1,(unsigned long)[self.PhotoImgArr count]];
[scrollView scrollToPageWithIndex:self.selected_index animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView1
{
if(scrollView1.tag ==0){
CGFloat pageWidth = scrollView1.frame.size.width;
current_page = floor((scrollView1.contentOffset.x - pageWidth / 2.0) / pageWidth) + 1;
self.index_lbl.text = [NSString stringWithFormat:#"%d of %lu",current_page+1,(unsigned long)[self.PhotoImgArr count]];
if(current_page+1==self.PhotoImgArr.count)
{
self.nextBtn.userInteractionEnabled=NO;
self.nextImg.image=[UIImage imageNamed:#"disable_next.png"];
}
else if(current_page==0)
{
self.prevBtn.userInteractionEnabled=NO;
self.prevImg.image=[UIImage imageNamed:#"disable_prev.png"];
}
else
{
self.nextBtn.userInteractionEnabled=YES;
self.prevBtn.userInteractionEnabled=YES;
self.nextImg.image=[UIImage imageNamed:#"next.png"];
self.prevImg.image=[UIImage imageNamed:#"prev.png"];
}
}
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView1 {
if([self.PhotoOrVideo isEqualToString:#"Photo"])
{
if([[scrollView1 viewWithTag:scrollView1.tag].subviews count]>0){
return [[scrollView1 viewWithTag:scrollView1.tag].subviews objectAtIndex:0];
}
}
return nil;
}
Please try the below code:
-(void)setScrollView:(UIScrollView *)scrollView
{
_scrollView=scrollView;
_scrollView.minimumZoomScale=0.2;
_scrollView.maximumZoomScale=3.0;
_scrollView.delegate=self;
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
[self.scrollView flashScrollIndicators];
}
I used to use these two lines to zoom out on the content of my scrollview. However since iOS8, I can't zoom out anymore. It does nothing.
Can someone explain to me why. I have autolayout turned off.
[scrollView setZoomScale:0.3 animated:YES];
scrollView.contentSize = CGSizeMake(tempSize.width*0.3, tempSize.height*0.3);
I am not sure if this will help you, but this method works for me when zooming in iOS 8. In this code, an imageView is in the scroll view.
- (void)viewDidLoad {
[super viewDidLoad];
self.scrollView.minimumZoomScale = 0.5;
self.scrollView.maximumZoomScale = 6.0;
self.scrollView.contentSize = self.PhotoView.frame.size;
self.scrollView.delegate = self;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.PhotoView;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView*)view atScale:(CGFloat)scale{
}
I'm trying for a while to build an ebook, flipping page (from left to right) and zooming.
So far I've tested a few projects but none of them was good enough to do both.
I've decided to build one of my own, so I started with basic flip animation like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.scrollView.delegate = self;
self.scrollView.maximumZoomScale = 5.0f;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
tapGesture.delegate = self;
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[self.scrollView addGestureRecognizer:tapGesture];
}
#pragma mark - UIScrollView Delegate
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
#pragma mark - UIGestureRecognizer Delegate
- (void)handleTap:(UITapGestureRecognizer *)tapGestur
{
NSLog(#"%s", __PRETTY_FUNCTION__);
if (tapGestur.state == UIGestureRecognizerStateEnded) {
[UIView transitionWithView:self.imageView duration:1 options:UIViewAnimationOptionTransitionFlipFromRight|UIViewAnimationOptionCurveEaseInOut animations:^{
if (!flipped) {
self.imageView.image = [UIImage imageNamed:#"2-IPAD-P.jpg"];
flipped = YES;
}
else {
self.imageView.image = [UIImage imageNamed:#"1-IPAD-P.jpg"];
}
} completion:^(BOOL finished) {
//
}];
}
}
What I'm trying to do now is transition flipping page (left to right) from the middle of the image.
Any idea how can I do this using UIVIew? Or maybe better options?
You should also give a look to CATansition. Have a look at this example.
Also, have you looked at UIViewAnimationOptions's UIViewAnimationOptionTransitionCurlUp and UIViewAnimationOptionTransitionCurlDown for page animations ?