Changing programatic uiscrollview to IB - ios

got a bit of a small problem here. I've been following this tutorial which creates an automatic scrolling slideshow using uiscrollview. This piece of code is used in my viewdidload -
UIScrollView *scr=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 120, 320, 180)];
scr.tag = 1;
scr.autoresizingMask=UIViewAutoresizingNone;
[self.view addSubview:scr];
[self setupScrollView:scr];
UIPageControl *pgCtr = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 280, 320, 60)];
[pgCtr setTag:12];
pgCtr.numberOfPages=10;
pgCtr.autoresizingMask=UIViewAutoresizingNone;
[self.view addSubview:pgCtr];
As you can see a small uiscrollview is created programatically which is 320x180. It works perfectly except for the fact that my UI has another uiscrollview which takes up the whole ui, which is around 320x700. I need to embed this programatically created scrollview into it, any ideas? Or alternatively I need to create my own scrollview using storyboards and link it across using code, but have no idea how I would go about this.
Any ideas would be much appreciated.

You have to embed the scroll view inside the scroll view not the main view
[self.scrollView addSubview:scr];

Related

UITapGestureRecognizer only triggered for starting area of UIScrollView

I have several sub views added to a UIScrollView in the main view controller. Each sub view's view controller has its own tap recognizer. The problem is, only tapping in the starting area on the screen is recognised. After scrolling the view and tapping beyond the starting area, the tapping handler will no longer be called.
This SO post UIButton in non-visible area of UIScrollView seems to be relevant but its solution description wasn't really clear to me...
A simple report project could be found at: dropbox link
Thanks.
Please check your contentview size or setbackground color for scrollview and contentview. Contenview size is not increasing i think.
I have downloaded your project and see that the
SSubViewController *pvc = [SSubViewController controllerWithSubViewID:0];
pvc frame is out of bound
SSubViewController *pvc = [SSubViewController controllerWithSubViewID:0];
[self.scrollView addSubview:pvc.view];
[self addChildViewController:pvc];
[pvc.view setBackgroundColor:[UIColor grayColor]];
[pvc.view setFrame:CGRectMake(0, 0, 400, 200)];
[pvc didMoveToParentViewController:self];
SSubViewController *pvc1 = [SSubViewController controllerWithSubViewID:1];
[self.scrollView addSubview:pvc1.view];
[pvc1.view setBackgroundColor:[UIColor yellowColor]];
[self addChildViewController:pvc1];
[pvc1 didMoveToParentViewController:self];
[pvc1.view setFrame:CGRectMake(0, 400, 400, 200)];
Now see the Colours
As you can see Gray color, and Yellow color frame

UIScrollView The view change at run

I'm trying to implement a ScrollView, but when I put a View inside, the View looks good in the preview but it's not the same when I run the application:
http://i.stack.imgur.com/ZZfEg.jpg
And I don't know how to resize a text of the width of the view.
Without the ScrollView I can do a good structured view but when I use ScrollView I cannot get a good view, how to do ?
Code here: http://pastebin.com/LN5FySku
I think this task is very easy if you use code rather than storyboard.
Use this code..
You can do this in Storyboard as well but i prefer using code for such tasks. Hope that helped.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 520)]; // little less than 568 to accommodate the tabBar
[scrollView setContentSize:CGSizeMake(320, 1500)];
UIView *largeView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 320, 100)];
[scrollView addSubview:largeView];
[self.view addSubview:scrollView];
for further more information check this link.
My problem is solved, the reasons:
UIImageView: I think my view have lost the images when i did a copy past of the view, so click on your UIImageView and set the image field.
UILabel: For the cropped text you have to create the Equal Width Constraint between the ContentView and the View, select the ContentView on the view hierarchy and Control + Drag to the View – you should get a pop-up that gives you the “Equal Widths” option.

iOS - Background view is consuming touch events

I'll start by describing how the screen looks. It is a UIPageViewController that covers 100% of the screen and a UIView (on top of the page vc) that covers 20% of the screen. Easy, right? basically UIView is over UIPageViewController.
So, I'm adding said UIPageViewController programatically to my view controller with self.view.addSubview(pageVC.view). but the UIView is defined in the interface builder
For this reason, since the UIPageViewController is added last it covers the UIView which forced me to call myUIView.layer.zPosition = 1 so that the UIView is visible.
The problem is any touch made on the UIView is instead consumed by the UIPageViewController. how can I solve this?
The layer property of a particular view is only used for the rendering of that specific view. That's the reason why changes to the layer won't impact anything regarding the interaction with that specific view.
However, the -sendSubviewToBack: and -bringSubviewToFront: methods on UIView were designed to achieve exactly what you are looking for. Here you can read the docs for them.
I wrote this piece of code so that you can test what this method is doing. Try to comment/uncomment the last line or changing the order in which the subviews are added to get a better understanding of how it works.
UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 150, 150)];
firstView.backgroundColor = [UIColor greenColor];
secondView.backgroundColor = [UIColor redColor];
[self.view addSubview:firstView];
[self.view addSubview:secondView];
UITapGestureRecognizer *firstTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(firstTap)];
UITapGestureRecognizer *secondTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(secondTap)];
[firstView addGestureRecognizer:firstTap];
[secondView addGestureRecognizer:secondTap];
[self.view sendSubviewToBack:secondView];

SVPullToRefresh custom view causes layoutIfNeeded go into infinite loop

I tried using custom views for the SVPullToRefresh but I've stumbled upon weird issue. I've made the demo project to illustrate the issue: https://github.com/gaks/SVRefreshProblem
The project is simply one UITableViewController with a TableView and the xib file with custom refresh bar view. The SVPullToRefresh is added to the tableView via the IBOutlet in the viewDidLoad: https://github.com/gaks/SVRefreshProblem/blob/master/SVRefreshProblem/DemoViewController.m
There is also a code that loads the RefreshBarView from the xib file and sets it as a custom view for SVPullToRefresh (for 'loading' state only for illustration):
RefreshBarView* refreshBarView = [[[NSBundle mainBundle] loadNibNamed:#"RefreshBarView" owner:self options:nil] objectAtIndex:0];
refreshBarView.bounds = CGRectMake(0, 0, 320, 60);
[[tableView pullToRefreshView] setCustomView:refreshBarView forState:SVPullToRefreshStateLoading];
The issue is that when you pull the table view to trigger the refresh it goes into infinite loop and eat-all-available-memory state after calling [self layoutIfNeeded] in the - (void)setState:(SVPullToRefreshState)newState. As far as I was able to debug it keeps calling - (void)layoutSubviews over and over.
What's weird is that when you open the xib file: https://github.com/gaks/SVRefreshProblem/blob/master/SVRefreshProblem/SVPullToRefresh/RefreshBarView.xib
... and remove the label from the view - it works just fine (except you have an empty view).
What am I doing wrong?
Loading from nibs is for ViewControllers, not views proper. You can try to do this programmatically which will work :
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
[v setBackgroundColor:[UIColor grayColor]];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
[label setText:#"asdf"];
[v addSubview:label];
[[tableView pullToRefreshView] setCustomView:v forState:SVPullToRefreshStateLoading];
Try to turn off "Use Auto Layout" in your nib.

How do I put images and text in the same layout in XCode

this is my first post. How can I add text and images to an app. i am only making an image, text and button based app and have made it for android as the picture shows below. I am now trying to do this in iOS but i am unable to place image after text followed by text again.
In android I was able to put multiple ImageView and TextViews inside a scroll layout, but I am unable to do this in storyboard Xcode 4.5/4.6.
If you could give me simple ideas to fix reproduce the same style of layouts in Xcode for iPhone and iPad, it would be great. I am not familiar with Xcode, so if it is possible to solve this easily, could you please help.
I want to be able to make a long scrollable page with many text line and images as you may have already understood from the image below.
Thanks in advance
Sorry was unable to post image. may try again or post website link.
You need to create a UIScrollView -> init UIScrollView with frame and add it to your app, set the content size of your scroll view.
Create the UILabel for the text. -> init UILabel with frame and text, add to your scroll view as a subview.
Create the UIImageView for the image -> init UIImageView with frame and image, add to your scroll view as a subview.
Typically, that is all if you do it in the way programmatically.
some code (without test):
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 50, 100)];
label1.text = #"label1";
[scrollView addSubview:label1];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 300, 500)];
imageView.image = [UIImage imageNamed:#"imagename.png"];
[scrollView addSubview:imageView];
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, label1.frame.size.height+imageView.frame.size.height);
[self.view addSubview:scrollView];
ps: If you want do it with nib, I could find some capture for you.

Resources