Problem when set new image in scroll view after zoom - iphone

I use below code for getting zoom image in the scroll view.
(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return photo;
}
but i have problem when i click on next button and set new image it also zoomed.
so it is possible the the next image is normal size. when i click on next button.

Try reseting the Zoom after the next scroll
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[scrollView zoomToRect:(CGRect)rect animated:(BOOL)animated]
// or
[scrollView setZoomScale:(float)scale animated:(BOOL)animated]
}

Related

Make it so the user has to scroll in a UIWebView

I have an application that is running on the iPhone that has a UIWebView on it. I load a webpage into this view and the user can continue to the next page by pressing buttons that I have added to a UIToolBar at the bottom of the page. What I am after is to stop the user from pressing these buttons until they have scrolled half way or all the way down the page. Is this possible?
If it's going to be half way down the page and further then you could probably use the content offset of the scroll view of the webview.
I would create an instance variable in your controller that references the scrollview of the webview. In iOS 5 you can use the webview.scrollView property to access the scrollView but in previous versions you would have to search the subviews of the webView.
if([_webView respondsToSelector:#selector(scrollView)]) {
_webViewScrollView = _webView.scrollView;
}
else {
for (UIView *subview in _webView.subviews) {
if ([subview isKindOfClass: [UIScrollView class]]) {
_webViewScrollView = subview;
break;
}
}
}
Then I would set the scrollviews delegate to be the controller I'm interested in
_webViewScrollView.delegate = self;
and implement the following delegate method:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if( scrollView.contentOffset.y > someValue ) {
// Enable Buttons
}
else {
// Make / Keep buttons inactive..
}
}
An alternative method would be to use some javascript and do some funky stuff with stringByEvaluatingJavaScriptFromString
use scrollView property of UIWebView and use its delegation call back
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
to handle the scrolling end event and UIScrollview property contentOffset can tell u that the scroll position with respect to its content size(actual size of ur webpage).
At the launch of application make your toolbar button disable. Then check for current scroll position by adding this line.
int position = [webView stringByEvaluatingJavaScriptFromString:#"window.scrollBy(0,180);"];
Once you scrolled your page to above specific position make your toolbar button enabled.
OR
You can use scroll view delegate methods.

issue while zooming content of UIScrollView

i am developing an application in which i am placing a set of images on a scrollView.i could place the images and given the contentSize as required to fit all the number of images.each imageView is of size 768,1024.i set the property of pagingEnabled to YES on the scrollview,to move to next image as the user swipes. i am loading each image into the imageview on scrolling the scrollView. i.e - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
issue:
the issue i face is when i zoom a UIImageView the imageView is getting zoomed but the zoomed imageView is being overlapped by its next imageView with its size assigned i.e 768,1024. i included the delegate methods as below.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [scrollView viewWithTag:tempTag-1];
}
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{
scrollView.pagingEnabled=NO;
[scrollView viewWithTag:tempTag].frame=CGRectMake(scrollView.contentSize.width-768, [scrollView viewWithTag:tempTag].frame.origin.y, [scrollView viewWithTag:tempTag].frame.size.width, [scrollView viewWithTag:tempTag].frame.size.height);
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
if (scrollView.zoomScale<=1) {
scrollView.pagingEnabled=YES;
}
}
i tried to change the frame of the next imageView to current ImageView depending on the content size but it didn't work.
can some one help me in this regard..
TNX in advance
You need to create a scrollView of sub-scrollviews to hold the imageViews. Then configure zoom on each sub-scrollviews.

UIScrollview zoom and enable paging simultaneously

Can i implement both the paging and zooming of imageview in a uiscrollview at the same time.
Yes. You can do it.
In each page of the mainScrollView add a subScrollView containing the imageView. You need to do the following things.
Set maximumZoomScale for subScrollView
[subScrollView setMaximumZoomScale:2.0f]; // You can set any value
This value is calculated based on the size of the image displayed in the imageView.
In the viewForZoomingInScrollView: method of the subScrollView return the imageView
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
Enable paging in mainScrollView
mainScrollView.pagingEnabled = YES;
You have to write further code to handle paging in the mainScrollView.

Zooming disturbing drawn UIImage in UIView

I have UIView in which I am drawing UIImage
- (void)drawRect:(CGRect)rect
{
[myImage drawInRect:rect];
}
This UIView is added on UIScrollView and returned as zoomable view i.e
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return iImageBgView;
}
Problem is coming when I do the zoom. Image which is drawn is getting shown pixelet i.e blur or disturbed. can anyone help me on "How to refresh / redraw this image"
I am manually refreshing / redrawing the image by calling
[self setNeedsDisplay];
but no use. seems like it is taking the previous coordinate and draw as per that instead of updated coordinate.
Thanks,
Sagar
This issue has been resolved by removing this UIView and adding it again on scrollview.
This has been done on
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
// Remove Imageview and add to Scrollview again
}

How to have images that do not resize when zooming in a UIScrollView?

I want to have images inside of a UIScrollView (or at least appear to be inside a UIScrollView) that don't change their size when zooming in and out. I do want the images to maintain their positions when zooming or scrolling.
The use case is that I have a customized map view with pushpins. I want the pushpins to stay in place when zooming and scrolling the map, but I don't want them to be "zoomed in" with the content.
What is the best way to do this?
You can have your pushpin image(s) as a subview of your UIScrollView but not a subview of the view returned by
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
Then, in scrollViewDidZoom adjust the pushpin x and y by the zoomScale to keep the pins correctly positioned:
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
imageView.frame = CGRectMake(pushPinX * scrollView.zoomScale, pushPinY * scrollView.zoomScale, imageView.frame.size.width, imageView.frame.size.height);
}