ios - The property frame of UIViewController's view doesn't work while using a single subview under UIScrollView -
before using uiscrollview's zoom feature, fine. code bellow:
uiscrollview* scrollview = [[uiscrollview alloc]init]; for(int i=0; < foodintrocount; ++i) { uiimage* image = [uiimage imagenamed:@"7_1.jpg"]; uiimageview * imgview = [[uiimageview alloc]initwithimage:image]; imgview.frame = cgrectmake(0, height*i, width, height); [scrollview addsubview:imgview]; } scrollview.contentsize = cgsizemake(width, height*(foodintrocount+1)) ; scrollview.pagingenabled = yes; scrollview.showsverticalscrollindicator = no; scrollview.showshorizontalscrollindicator = no; scrollview.bounces = no; scrollview.delegate = self; _foodwineviewcontroller = [[ohfoodwineviewcontroller alloc]initwithcategorydata:_fooddata]; uiview* wineview = _foodwineviewcontroller.view; wineview.frame = cgrectmake(0, height*(foodintrocount), width, height); [scrollview addsubview:wineview];
after adding zoom feature, code looks like:
uiscrollview* scrollview = [[uiscrollview alloc]init]; uiview* zoomview = [[uiview alloc]init]; for(int i=0; < foodintrocount; ++i) { uiimage* image = [uiimage imagenamed:@"7_1.jpg"]; uiimageview * imgview = [[uiimageview alloc]initwithimage:image]; imgview.frame = cgrectmake(0, height*i, width, height); [zoomview addsubview:imgview]; } scrollview.contentsize = cgsizemake(width, height*(foodintrocount+1)) ; scrollview.pagingenabled = yes; scrollview.showsverticalscrollindicator = no; scrollview.showshorizontalscrollindicator = no; scrollview.bounces = no; scrollview.delegate = self; scrollview.maximumzoomscale = 2.0; _foodwineviewcontroller = [[ohfoodwineviewcontroller alloc]initwithcategorydata:_fooddata]; uiview* wineview = _foodwineviewcontroller.view; wineview.frame = cgrectmake(0, height*(foodintrocount), width, height); [zoomview addsubview:wineview]; [scrollview addsubview:zoomview];
the problem is: wineview displayed on first page, not on foodintrocount+1 page.
your code should consider previous y position , height both if want add subview 1 after vertically. code should below
imgview.frame = cgrectmake(0, height*i+y, width, height);
the code isn't tested though, try this..
Comments
Post a Comment