UscrollView: bad scroll on iPhone 6 plus - ios

I have a problem. I use a UIScrollView with 1 image and 2 tableview inside.
The scroll works correctly on an iPhone 5 but on an iPhone 6Plus the scroll has a problem not so easy to explain. If I tap in light way the scroll is ok, but if I tap in a little long way the screen the scroll doesn't works. Here the code that I used.
self.scrollView = [[UIScrollView alloc] initWithFrame:self.frame];
self.scrollView.scrollEnabled = YES;
self.scrollView.delegate = self;
[self addSubview:self.scrollView];
self.theImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, lenghtImage, hightImage)];
self.theImage.image = [UIImage imageNamed:#"theImage.png"];
[self.scrollView addSubview:self.theImage];
self.tableA = [[UITableView alloc] initWithFrame:CGRectMake(0, yPosA, self.bounds.size.width, heightA];
self.tableA.delegate = self;
self.tableA.dataSource = self;
self.tableA.scrollEnabled = NO;
[self.scrollView addSubview:self.tableA];
self.tableB = [[UITableView alloc] initWithFrame:CGRectMake(0, yPosB, self.bounds.size.width, hightB)];
self.tableB.delegate = self;
self.tableB.dataSource = self;
self.tableB.scrollEnabled = NO;
[self.scrollView addSubview:self.tableB];
self.scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, heightA + heightB);

can your tableviews be eating the touches? have you tried with tableView.userInteractionEnabled = false to see if it works ?

Related

UIScrollView doesn't scroll in the bottom part of screen

I'm using a UIScrollView with 1 image and 2 tableview inside. The scroll works correctly if I tap on the center and on the top of the screen but doesn't works if I try to scroll tapping on the bottom of the screen. Here the code that I used.
self.scrollView = [[UIScrollView alloc] initWithFrame:self.frame];
self.scrollView.scrollEnabled = YES;
self.scrollView.delegate = self;
[self addSubview:self.scrollView];
self.theImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, lenghtImage, hightImage)];
self.theImage.image = [UIImage imageNamed:#"theImage.png"];
[self.scrollView addSubview:self.theImage];
self.tableA = [[UITableView alloc] initWithFrame:CGRectMake(0, yPosA, self.bounds.size.width, heightA];
self.tableA.delegate = self;
self.tableA.dataSource = self;
self.tableA.scrollEnabled = NO;
[self.scrollView addSubview:self.tableA];
self.tableB = [[UITableView alloc] initWithFrame:CGRectMake(0, yPosB, self.bounds.size.width, hightB)];
self.tableB.delegate = self;
self.tableB.dataSource = self;
self.tableB.scrollEnabled = NO;
[self.scrollView addSubview:self.tableB];
self.scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width,heightImage+heightTableA+heightTableB);
Your scroll view contentSize should be equal or greater than its total subview size.
You calculate contentSize height by adding all of its subview height and also their y coordinate.
so it should be:
self.scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, hightImage + yPosA + heightA + yPosB + hightB);

Image not shown on vertical-scrollView in a background horizontal-scrollView

I would like to show let's say 3 long pictures (longer than iPhone's screen height) in a big background UIScrollView horizontally, and since each picture is longer than the screen height, so I put another 3 Sub-UIScrollView that are for vertical swiping in the background one.
I setup the background one like this:
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
_scrollView.delegate = self;
_scrollView.contentSize = CGSizeMake(screenWidth*_count, screenHeight);
_scrollView.pagingEnabled = YES;
_scrollView.alwaysBounceVertical = NO;
_scrollView.alwaysBounceHorizontal = YES;
And I setup each Sub-UIScrollView like this:
if (imageHeight > screenHeight) { //requiring extra scrollView to support
UIImageView *longImgView = [[UIImageView alloc] init];
[longImgView setFrame:CGRectMake(originX, 0, screenWidth, imageHeight)];
longImgView.image = _image;
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(originX, 0, screenWidth, screenHeight)];
[scrollView setContentSize:CGSizeMake(screenWidth, imageHeight)];
[scrollView setContentOffset:CGPointMake(originX, 0)];
scrollView.backgroundColor = [UIColor blueColor];
scrollView.alwaysBounceVertical = YES;
scrollView.alwaysBounceHorizontal = NO;
[scrollView addSubview:longImgView];
[_scrollView addSubview:scrollView];
}
Please notice that I set scrollView.backgroundColor = [UIColor blueColor]; to highlight this sub-scrollView, but when I run it, I can only see the blue-colored sub-scrollView, I cannot see the picture showing (longImgView.image = _image;).
UPDATE: I can see the memory address allocated to the _image with break point and console. Also I can see the sub-scrollView has set the same contentSize as the image size but only cannot see the image itself.
Wait: [longImgView setFrame:CGRectMake(originX, 0, screenWidth, imageHeight)];
make that:
[longImgView setFrame:CGRectMake(0, 0, screenWidth, imageHeight)];

Why am I unable to zoom my UIImageView embedded in a UIScrollView?

I literally have the most basic of code and I'm so frazzled as to why it won't zoom:
- (void)viewDidLoad
{
[super viewDidLoad];
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds))];
self.scrollView.delegate = self;
self.scrollView.contentSize = self.imageView.bounds.size;
self.scrollView.minimumZoomScale = 0.5;
self.scrollView.maximumZoomScale = 10.0;
[self.view addSubview:self.scrollView];
self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"community1.jpeg"]];
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.scrollView addSubview:self.imageView];
}
In the simulator I try to zoom and nothing at all happens. It's a rather large image if that's relevant.
Did you implement -viewForZoomingInScrollView: in your scroll view's delegate? If not, you need to do that, returning the view you want to actually zoom when you pinch.

Arrange UIscrollView to back

Maybe a huge noob question but i cant seem to figure it out, even after some time googling i cant find out to arrange a scrollview underneeth a navigation bar.
My code:
- (void)loadView {
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scroll.backgroundColor = [UIColor blackColor];
scroll.delegate = self;
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Plattegrond DeFabrique schematisch.png"]];
scroll.contentSize = image.frame.size;
[scroll addSubview:image];
scroll.minimumZoomScale = scroll.frame.size.width / image.frame.size.width;
scroll.maximumZoomScale = 2.0;
[scroll setZoomScale:scroll.minimumZoomScale];
self.view = scroll;
}
Try inserting the view behind the superview or try sendSubviewToBack.
[[self.view superview] insertSubview:scroll belowSubview:self.view];
or
[self.view sendSubviewToBack:scroll];
It sounds like you are just wanting to add the scroll view to the self.view though. Do as the other answer suggest and create the scrollView from the self.view frame then add it to your self.view.
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame]; // Thilina
[self.view addSubview:scroll];
Since you are passing the frame of [UIScreen mainScreen] at the time of allocating the UIScrollView , the size of UIScrollView is overlapping the UINavigation . Replace it with
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
also rather than replacing the self.view with the scrollView , try to add the scrollView as subview on self.view
[self.view addSubview:scrollView];
Do the following task in the viewDidLoad
Hope it will help you.
You can simply use the self.view's frame when creating the ScrollView. This will solve your problem.
- (void)loadView {
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame];
scroll.backgroundColor = [UIColor blackColor];
scroll.delegate = self;
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Plattegrond DeFabrique schematisch.png"]];
scroll.contentSize = image.frame.size;
[scroll addSubview:image];
scroll.minimumZoomScale = scroll.frame.size.width / image.frame.size.width;
scroll.maximumZoomScale = 2.0;
[scroll setZoomScale:scroll.minimumZoomScale];
[self.view addSubView:scroll]; //MarkM
}

UIScrollView programmatically Scrolling

I have a UITextView inside a UIScrollView that needs to automatically scroll once the user starts editing it. This is because the keyboard will cover the textview.
Here is the code -
In viewDidLoad:
feedBackformView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, segmentedControl.frame.origin.x + self.segmentedControl.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
feedBackformView.backgroundColor = [UIColor whiteColor];
feedBackformView.scrollEnabled = YES;
feedBackformView.delegate = self;
feedBackformView.userInteractionEnabled = YES;
feedBackformView.showsVerticalScrollIndicator = YES;
feedBackformView.contentSize = CGSizeMake(320, 700);
commentsView = [[UITextView alloc] initWithFrame:CGRectMake(5, emailField.frame.origin.y + 40, 250, 150)];
commentsView.delegate = self;
commentsView.layer.borderWidth = 2.0f;
commentsView.layer.cornerRadius = 5;
and here's the delegate method implementation -
-(void)textViewDidBeginEditing:(UITextView *)textView{
CGPoint point = textView.frame.origin;
[scrollView setContentOffset:point animated:YES];
}
However, nothing happens.
your are doing fine but use feedBackformView instead of scrollView,while setting content offset in textViewDidBeginEditing:method, just have a look on below code
feedBackformView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, 320, 200)];
feedBackformView.backgroundColor = [UIColor whiteColor];
feedBackformView.scrollEnabled = YES;
feedBackformView.delegate = self;
feedBackformView.userInteractionEnabled = YES;
feedBackformView.showsVerticalScrollIndicator = YES;
feedBackformView.contentSize = CGSizeMake(320, 700);
commentsView = [[UITextView alloc] initWithFrame:CGRectMake(5, 40, 250, 150)];
commentsView.delegate = self;
commentsView.layer.borderWidth = 2.0f;
commentsView.layer.cornerRadius = 5;
[feedBackformView addSubview:commentsView];
[self.view addSubview:feedBackformView];
in textview DelegateMethod,
-(void)textViewDidBeginEditing:(UITextView *)textView{
CGPoint point = textView.frame.origin;
[feedBackformView setContentOffset:point animated:YES];
}
hope it will hepls you...
You can use scrollView scrollRectToVisible:animated or the setContentOffset:animated methods described here:
UIScrollView Class Reference
Keep in mind that UITextView comes with its own scroll view. so you may not need to nest it inside another scrollview. But you may need to if your app is that interesting.
Is your point of scrolling already at a visible point?
-(void)textViewDidBeginEditing:(UITextView *)textView{
// try this instead
CGPoint point = CGPointMake(textView.frame.origin.x,
textView.frame.origin.y + textView.frame.size.height);
[scrollView setContentOffset:point animated:YES];
// What does this produce?
NSLog(#"%# %#", NSStringFromCGPoint(scrollView.contentOffset),
NSStringFromCGRect(textView.frame));
}

Resources