Up vote 0 down vote favorite 1 share g+ share fb share tw.
I've got some problem with a UIScrollView and this is the only problem , disturbs me to submit my application to AppStore,people,please,help! I add a scrollview and pageController in viewDidLoad of UIViewController; A subview of a scrollview contains maximum 6 UIImageViews (images previews, 6 per page). When any of that 6 detects a touch it loads an image in its normal size.
First time it works perfect,but then,after returning to the previous view controller, containing a uiscrollview, from the navigation bar those 6 views "jumps" to the top,so,the part of the images located under a navigation bar and make difficult for user to see it. I've changed the background color of uiscrollview and discovered that this happens because a scrollview content size increases in some way,that I don't understand. Please,if anyone knows how to solve the problem,help me!
Here is the code: - (void)viewDidLoad { NSString *category=self. Title; NSNumberFormatter *f=NSNumberFormatter alloc init; f setNumberStyle:NSNumberFormatterDecimalStyle; categoryID=f numberFromString:category intValue; f release; self createDatabaseConnection; self readCategoryFromDatabase; self. Title=self categoryName; //Define the n umber of pages in a scroll view unsigned int num=(self.
CategoryContent count)%numberOfImagesPerPage; if (num==0) { kNumberOfPages=self. CategoryContent count/numberOfImagesPerPage; } else { kNumberOfPages=(self. CategoryContent count/numberOfImagesPerPage)+1; } NSLog(@"View width is :%f ,View height is:%f",self.view.frame.size.
Width, self.view.frame.size. Height); imageScrollView = UIScrollView alloc initWithFrame:CGRectMake(0, 0, self.view.frame.size. Width, self.view.frame.size.
Height); imageScrollView. PagingEnabled = YES; imageScrollView. ContentSize = CGSizeMake(imageScrollView.frame.size.
Width * kNumberOfPages, imageScrollView.frame.size. Height); //imageScrollView setContentOffset:CGPointZero; imageScrollView. ShowsHorizontalScrollIndicator = NO; imageScrollView.
ShowsVerticalScrollIndicator = NO; imageScrollView. ScrollsToTop =NO; imageScrollView. Delegate = self; NSLog(@"ScrollView x is :%f ,s scrollview y is:%f",self.imageScrollView.frame.origin.
X, self.imageScrollView.frame.origin. X); pageControl = UIPageControl alloc initWithFrame:CGRectMake(0, 350, 320, 80); pageControl. NumberOfPages = kNumberOfPages; pageControl.
CurrentPage = 0; pageControl. UserInteractionEnabled =YES; pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged; //Init controllers array with nulls objects NSMutableArray *controllers = NSMutableArray alloc init; for (unsigned I = 0; I = kNumberOfPages) return; //Build pages array; int savePageNumber=0; for (int i=0; iself. CategoryContent count) { maxMargin=self.
CategoryContent count; } NSMutableArray *images=NSMutableArray alloc init; self. ArrayImages=NSMutableArray alloc init; for (int j=savePageNumber; j ArrayImages=images; PageViewController *nextController=PageViewController alloc initWithPageNumberAndImages:i :self. ArrayImages; nextController.
Title=self. Title; viewControllers replaceObjectAtIndex:i withObject:nextController; nextController release; images release; self. ArrayImages release; if (maxMargin==self.
CategoryContent count) { break; } } // replace the placeholder if necessary PageViewController *controller = viewControllers objectAtIndex:page; if ((NSNull *)controller == NSNull null) { controller = PageViewController alloc initWithPageNumberAndImages:page :self. ArrayImages; viewControllers replaceObjectAtIndex:page withObject:controller; controller release; } // add the controller's view to the scroll view if (nil == controller.view. Superview) { CGRect frame = imageScrollView.
Frame; frame.origin. X = frame.size. Width*page; frame.origin.
Y =0; controller.view. Frame = frame; imageScrollView addSubview:controller. View; } } -(void) changePage:(id)sender { int page = pageControl.
CurrentPage; // load the visible page and the page on either side of it (to avoid flashes when the user starts scrolling) self loadScrollViewWithPage:page - 1; self loadScrollViewWithPage:page; self loadScrollViewWithPage:page + 1; // update the scroll view to the appropriate page CGRect frame = imageScrollView. Frame; frame.origin. X = frame.size.
Width*page; frame.origin. Y = 0; imageScrollView scrollRectToVisible:frame animated:YES; // Set the boolean used when scrolls originate from the UIPageControl. See scrollViewDidScroll: above.
PageControlUsed = YES; } #pragma mark- UIScrollView Delegate protocol - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { UIView *view = nil; if (scrollView == imageScrollView) { view = imageScrollView viewWithTag:ZOOM_VIEW_TAG; } return view; } Any ideas? Thanks a lot! Iphone uiscrollview contentsize link|improve this question asked Aug 13 '11 at 18:35mariad1.
Its confusing trying to understand what you wrote. You speak of returning to a previous view controller... you mean to say you have 2 view controllers, both with the same scrollview? I did not understand that part, so please clarify.
Another thing: all your app view controllers are part of a navigation controller stack, all showing a navigation bar at the top? – Leuguimerius Aug 13 '11 at 20:49 Yes,the navigation bar appears in every view controller. I have one view controller containing scroll view.
The scrollview contains 6 image views. Everyone of them has a gesture recognizer ,which recognizes the tap. When it tapped I load another view controller displaying the whole image.
No scrollviews in it,only an image itself. And when I return to a first controller i've got these 6 image views at the top of the screen,at (0,0) and not below the navigation bar,as it appeared first time this view controller was loaded – mariad Aug 13 '11 at 21:37 Ok, much clearer now. Do you mean to say that all image views appear as stacked on top of each other at (0,0), so actually you can only see one view?
– Leuguimerius Aug 13 '11 at 21:49 No, I see all 6 of them. They are 2 rows, 3 imageviews in a row. After returning from a whole image view to previews the 3 of them that located in a first row obscured by a navigation bar.
Though it is a translucent bar it creates a bad user experience,so I need to fix it somehow. Talking about (0,0) I meant that the left top point of the view that contains 6 previews is (0,0) and not (0,64), so it is not under the navigation bar,but at the top of the screen – mariad Aug 13 '11 at 22:10 Try changing the line where you set the contentSize of you scrollview to this one: imageScrollView. ContentSize = CGSizeMake(self.frame.size.
Width * kNumberOfPages, self.frame.size. Height); – Leuguimerius Aug 13 '11 at 22:31.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.