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)];
Related
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 ?
The scroll is covering the time and carrier , I just want it not to overlapp but the image view should finish below the carrier bar .
How can this be done.
This is my code for the same
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320 , self.view.frame.size.height)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
UIImage *image = [UIImage imageNamed:#"dora.jpeg"];
UIGraphicsBeginImageContext(CGSizeMake(320, 480));
[image drawInRect:CGRectMake(0, 0, 320, 480)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView = [[UIImageView alloc] initWithImage:image];
CGRect frame = imageView.frame;
frame.origin.y -= 130;
defaultY = frame.origin.y;
imageView.frame = frame;
self.tableView.backgroundColor = [UIColor clearColor];
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 170)];
header.backgroundColor = [UIColor clearColor];
self.tableView.tableHeaderView = header;
[self.view addSubview:imageView];
[self.view addSubview:self.tableView];
defaultSize = CGSizeMake(50, 20);
scrollPanel = [[UIView alloc] initWithFrame:CGRectMake(-defaultSize.width, 0, defaultSize.width, defaultSize.height)];
scrollPanel.backgroundColor = [UIColor blackColor];
scrollPanel.alpha = 0.45;
Thanks
This issue can be very frustrating, and I believe it is a bug on Apple's end, especially because it shows up in their own pre-wired TableViewController from the object library.
For more info refer
iOS 7: UITableView shows under status bar
Set the origin.y of your scrollView (or table) to height of the status bar:
CGRect scrollControllFrame = scrollControll.frame;
scrollControllFrame.origin.y = [UIApplication sharedApplication].statusBarFrame.size.height;
scrollControllFrame.size.height-=[UIApplication sharedApplication].statusBarFrame.size.height;
scrollControll.frame = scrollControllFrame;
So I have a UIScrollView set up the following way and for some reason, the scroll view is displayed like this:
Phone Screen
---------------
---------------|---------------|
---------------|---------------|
---------------|---------------|
---------------|----Content----|
---------------|---------------|
---------------|---------------|
---------------|---------------|
---------------|---------------|
---------------
My goal is to have the user scroll to the right, like below:
Phone Screen
---------------
|---------------|---------------
|---------------|---------------
|---------------|---------------
|----Content----|---------------
|---------------|---------------
|---------------|---------------
|---------------|---------------
|---------------|---------------
---------------
Here's how the scroll view is set up (this is a bit simplified, but accurate):
CGFrame frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
CGSize contentSize = CGSizeMake(self.bounds.size.width*2, self.bounds.size.height);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame];
scrollView.contentSize = contentSize;
scrollView.propertyN = bool; //E.g. pagingEnabled, bounces, clipsToBounds, etc.
UIImageView *imageView = [[UIImageView alloc] initWithImage:someImage];
imageView.frame = frame;
[scrollView addSubview:imageView];
[self.view addSubview:scrollView];
Has anyone else had this problem? I'm sure I'm making some extremely basic mistake in my setup of the scroll view but can't seem to spot it.
Could the the origin for self.view.frame be offscreen (e.g. -self.bounds.width)?
I'd try starting with simple code and building back up to what you want. Here's some simple code that's similar to the code above that you can throw in a blank project to convince yourself that the code you posted isn't the likely culprit:
CGFloat width = self.view.bounds.size.width;
CGFloat height = self.view.bounds.size.height;
CGRect frame = CGRectMake(0.0f,0.0f,width,height);
CGSize contentSize = CGSizeMake(width*2, height);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame];
scrollView.backgroundColor = [UIColor yellowColor];
scrollView.contentSize = contentSize;
scrollView.pagingEnabled = YES;
UIView *view1 = [[UIView alloc] initWithFrame:frame];
view1.backgroundColor = [UIColor blueColor];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(width,0.0f,width,height)];
view2.backgroundColor = [UIColor greenColor];
[scrollView addSubview:view1];
[scrollView addSubview:view2];
[self.view addSubview:scrollView];
I have a UIScrollView like so:
self.view.backgroundColor = [UIColor redColor];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++) {
CGFloat xOrigin = i * self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:awesomeView];
}
[scroll setShowsHorizontalScrollIndicator:NO];
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:scroll];
This is the right gestures I want and is fine for a finite set of custom subviews, but how do I make the scollview go infinite?
I want the subviews to be dates and swiping left and right will bring the next or previous date.
Either use UIScrollViewDelegate method -(void)scrollViewDidScroll:(UIScrollView*)scrollView and adjust your view positions and the scrollviews content offset there, or have a look at Apple's example on how to create a infinite horizontal ScrollView by subclassing the UIScrollView: https://developer.apple.com/library/ios/samplecode/StreetScroller/
Please tell me how to set scrollview inside a scrollview like nested process.
The following code works partially.
int x=10;
int y=10;
for(int i=0; i<5; i++)
{
UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, 50, 50)];
scrollview.showsVerticalScrollIndicator=YES;
scrollview.scrollEnabled=YES;
scrollview.userInteractionEnabled=YES;
scrollview.backgroundColor = [UIColor greenColor];
[self.view addSubview:scrollview];
scrollview.contentSize = CGSizeMake(50,50);
y=y+95;
}
Now all I can see are 3 scrollviews and the others are hidden. How can I create main scroll to view so that the child scrollViews are not hidden?
You need to have an initial scrollView that you then put these scrollViews in.
UIScrollView * mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
mainScrollView.contentSize = CGSizeMake(50, (y + 95) * 5);
// further configure
[self.view addSubview: mainScrollView];
Then change
[self.view addSubview:scrollview];
To
[mainScrollView addSubview: scrollView];
//I have created Two Scroll view programmatically this way
UIScrollView *scrollViewOuter = [[UIScrollView alloc] initWithFrame:CGRectMake(100.0f, 100.0f, 600.0f, 600.0f)];
scrollViewOuter.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
scrollViewOuter.contentSize = CGSizeMake(2000.0f, 2000.0f);
UIScrollView *scrollViewInner = [[UIScrollView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 200.0f, 200.0f)];
scrollViewInner.backgroundColor = [UIColor whiteColor];
scrollViewInner.contentSize = CGSizeMake(2000.0f, 2000.0f);
[scrollViewOuter addSubview:scrollViewInner];
[self.window addSubview:scrollViewOuter];
//You can change frame and use in your own way
Just create a parent scrollview that is big enough to hold the 5 smaller ones, then change this line:
[self.view addSubview:scrollview];
to
[parentScrollView addSubview:scrollview];