Thursday 15 July 2010

ios - Enable zooming in a uiscrollview with paging enabled and scrolling enabled -



ios - Enable zooming in a uiscrollview with paging enabled and scrolling enabled -

i have uiscrollview load array of images in order can scroll through pictures effect similar photos effect in ios. using code:

nsarray *paths = nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes); nsstring *path = [paths objectatindex:0]; nsstring *imagefilepath = [path stringbyappendingpathcomponent:@"newpics"]; fileexists = [[nsfilemanager defaultmanager] fileexistsatpath:imagefilepath]; if(fileexists){ imgs=[[nsmutablearray alloc]init]; [imgs addobject:[uiimage imagewithcontentsoffile:[path stringbyappendingpathcomponent:@"newpics/pic1.png"]]]; [imgs addobject:[uiimage imagewithcontentsoffile:[path stringbyappendingpathcomponent:@"newpics/pic2.png"]]]; [imgs addobject:[uiimage imagewithcontentsoffile:[path stringbyappendingpathcomponent:@"newpics/pic3.png"]]]; [imgs addobject:[uiimage imagewithcontentsoffile:[path stringbyappendingpathcomponent:@"newpics/pic4.png"]]]; cgsize imagesize; imagesize.height = 648; imagesize.width = 927; self.scroll1.frame = cgrectmake(0,0,imagesize.width,imagesize.height); self.scroll1.contentsize = cgsizemake(imagesize.width * imgs.count, imagesize.height ); self.scroll1.minimumzoomscale=1.0; self.scroll1.maximumzoomscale=3.0; self.scroll1.pagingenabled = yes; self.scroll1.delegate=self; cgfloat xpos = 0.0; (uiimage *image in imgs) { imageview = [[uiimageview alloc] initwithimage:image]; imageview.frame = cgrectmake(xpos, 0.0, imagesize.width, imagesize.height); [self.scroll1 addsubview:imageview]; xpos += imagesize.width; } } - (uiview *)viewforzoominginscrollview:(uiscrollview *)scrollview { int positionscrollprim = scrollview.contentoffset.x; int positionscroll = positionscrollprim / 927 ; imageview = [[uiimageview alloc] initwithimage:[imgs objectatindex:positionscroll]]; //uiimage *tmep = [imgs objectatindex:1]; homecoming imageview; }

i can't accomplish right result, instead bunch of weird behaviors such wrong zooming , no more scrolling when seek zoom. guess problem in viewforzoominginscrollview section, that's why tried solve using above code. can't create work. missing?

the mutual approach utilize 2 scroll views: outer 1 scrolls through images , each image wrapped in scroll view responsible zooming.

ios objective-c uiscrollview

No comments:

Post a Comment