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
}
Related
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.
what I would like to do is to build a UIScrollView which contains a lots of images, the problem is that I don't want to load all the images to the scroll view at once for performance issues, so if someone can suggest and help me to build a UIScrollView which can add images on runtime, for example when I scroll left I get image and the next image is allocated when needed, paging on.
Use this delegate method for add new image.
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
// called on finger up if user dragged. decelerate is true if it will continue moving afterwards
You can implement UIScrollViewDelegate and use its methods like
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
which tells you about any offset changes in the Scroll View, and then you can load whichever image should appear at that offset at run-time. For that, you would have to keep track of the current offset and the page of your scroll view.
Look into the Apple's PageControl Sample Code
This could be a good starting point
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
float currPos = scroll.contentOffset.x;
BOOL movingRight = ( currPos / scroll.frame.size.width ) > 1 ? YES : NO ;
if (movingRight) {
NSLog(#"RIGHT");
[photo2 setImage:[UIImage imageNamed:#"22.jpg"]];
photo2.frame = CGRectMake(scroll.frame.size.width * 2, 0, scroll.frame.size.width, scroll.frame.size.height);
}else{
NSLog(#"LEFT");
[photo2 setImage:[UIImage imageNamed:#"33.jpg"]];
photo2.frame = CGRectMake(0, 0, scroll.frame.size.width, scroll.frame.size.height);
}
//NSLog(#"%f",currPos);
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
UIImage *img = [photo1 getImage];
[photo1 setImage:[photo2 getImage]];
[self.scroll scrollRectToVisible:CGRectMake(self.scroll.frame.size.width, 0, self.scroll.frame.size.width, self.scroll.frame.size.height) animated:NO];
[photo2 setImage:img];
}
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]
}
I created a UIScrollView with a CATiledLayer for a 10000x8078 image.
Would I place this image in a UIView the zoomScale is always updated according to the contentSize (respectively the size of the image).
With CATiledLayer the contentSize now varies according to the tiles in use.
How can I now determine the correct zoomScale of the UISrcollView?
Thanks
What has worked for me, based on the the ZoomingPDFViewer Sample Code, is to keep tabs on the zoom manually the following way in the UIScrollView delegate:
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
scrollView.scrollEnabled = YES;
// set the new scale factor for the TiledPDFView
pdfScale *=scale;
....
I have a UIScrollView with nested UIImageViews. Each imageview can zoom, but when I try to scroll the inner scrollview while zoomed on the image, the outer scrollview picks it up and switches imageviews.
How can I prevent this from happening so that the outer scrollview only scrolls when the inner is not zoomed?
I will post my answer that I got to work to help others out.
One easy way to handle nested UIScrollViews is to share the same delegate. This way, when you detect one UIScrollView scrolling, you can easily share controller logic and apply settings to the other.
to solve this particular problem I was having, All I had to do was keep a BOOL with the current zoom state. Once the app detected that the inner scrollview was zooming,
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView1 {
return [innerScrollViews objectAtIndex:[self indexOfComicViewWithOffset:currentOffset]];
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView1 withView:(UIView *)view atScale:(float)scale {
if (scale == 1) {
zooming = NO;
[outerScrollView setScrollEnabled:YES];
} else {
zooming = YES;
[outerScrollView setScrollEnabled:NO];
}
}