Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView in Navigation Controller
    primarykey
    data
    text
    <p>I'm trying to get UIScrollView working in my training app. Scroll itself works fine, but if I'm using a Navigation Controller, the content area of the SVC is shifted downwards for amount of navigation bar height.</p> <p><img src="https://i.stack.imgur.com/UXuLW.png" alt="without nav controller"> <img src="https://i.stack.imgur.com/LyeNa.png" alt="with nav controller"></p> <p>Cyan area is UIScrollView background. contentSize is set properly, only swiping pages side to side is allowed. This is how I add an image to scroll view</p> <pre><code>CGSize scrollViewSize = self.scrollView.frame.size; UIImage * image = [UIImage imageWithContentsOfFile:[cachesDirectory stringByAppendingFormat:@"/%@", fileName]]; CGFloat imageOriginalWidth = image.size.width; CGFloat imageOriginalHeight = image.size.height; CGFloat imageOffsetX = 10; CGFloat imageDisplayedWidth = scrollViewSize.width - (2 * imageOffsetX); CGFloat imageDisplayedHeight = imageOriginalHeight / imageOriginalWidth * imageDisplayedWidth; CGFloat imageOffsetY = (scrollViewSize.height - imageDisplayedHeight) / 2; CGRect viewFrame = CGRectMake(scrollViewSize.width * (filmIndex) + imageOffsetX, imageOffsetY, imageDisplayedWidth, imageDisplayedHeight); contentAreaHeight = imageDisplayedHeight; UIImageView * view = [[UIImageView alloc] initWithFrame:viewFrame]; view.backgroundColor = [UIColor greenColor]; view.image = image; view.contentMode = UIViewContentModeScaleAspectFit; view.tag = filmIndex; [self.scrollView addSubview:view]; </code></pre> <p>And this is how I set content size and offset</p> <pre><code>self.scrollView.contentSize = CGSizeMake(scrollViewSize.width * ([self.filmsData count]), contentAreaHeight); self.scrollView.contentOffset = CGPointMake(scrollViewSize.width * [self.filmsData count] / 2, 0); </code></pre> <p>How what's wrong with my code and how can I get images centered vertically when using navigation controller?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload