make scroll view glitch in xcode? - ios

so i was making a scroll view in my app so i can have more content showing in one view. the storyboard has a lot of text, 1 picture, and 3 buttons at the end. every time i scroll all the way to the button and click on one of them it takes me to the corresponding storyboard but than when i click the button to go back to the main storyboard with all the content, it doesn't led me scroll back to the top. this is all the code in the .m file for the scroll view:
-(void)viewDidAppear:(BOOL)animated{
[myScroll setScrollEnabled:YES];
[myScroll setContentSize:CGSizeMake(320, 940)];
}
this is the code in the .h file for the scroll view:
#interface SimplifyingNumericlaExpressionsViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIScrollView *myScroll;
#end
is there any way i coud set the default coordinates of the scroll view of when it is being view? or something that can fox that?
herei s the link of a video showing the problem http://youtu.be/TgTaiEEhPhc
any idea or example counts. im a beginner :(
thanks!
UPDATE
i tried putting the same code i had in the viewDidLoad and this is what happen:
http://youtu.be/R6M4gGyLxgQ
im now having a different problem, it doesn't scroll all the way down and even though i tried changing the values it still doesn't work. any help? thanks!

the things you are doing should be done in viewDidLoad not viewDidAppear. I would assume the bug is comming from the fact your scroll view was super low already when you set the content size possibly reanchoring your scrollView lower?

Related

UITableView frame postion incorrect when view loads

I have a UITableViewController, one level deep inside a UINavigationController. The rootviewController is a slide out menu - library over here: https://github.com/mobivery/MVYSideMenu
The problem
When the UiTableViewController loads - its in the incorrect position and after half a second, it moves down to the correct position by it self. Looks really odd.
So, as a test, I created a new UIViewController with only boiler plate code and put it one level deep in the UiNavigationController. I then added a UIbutton to it and when the view loads, the button is always in the correct position.
So, I then added a UITableView to this UIViewController and positioned it half way down the screen. I also manually added auto layout constraints to it.
Now, re running the test - the exact same thing happens - the UITableView starts out just above its original position, and half a second later, it moves down to its correct position.
Can anyone tell me why this is happening and what could cause it?
Thanks!

Elusive UIView Subclass Name

This one is really bugging me! What is the name of this UIView subclass? I'm not talking about the compass itself, but the two dots at the bottom of the view. I know it's not a private API because I have seen it before. Or am I confused and this is not a UIView at all, but a UIViewController. Which UIView / UIViewController subclass is shown here. It acts like a UIScrollView, but has distinct pages, and has the dots at the bottom of the screen that show the users relative progress through the pages. I have checked this link about UIView subclasses, but became lost after about the 45th one. http://www.themusingsofalostprogrammer.com/2010/09/list-of-every-uiview-subclass.html
(source: tqn.com)
Thankyou for your time.
It is a UIPageControl. It corresponds (or is supposed to correspond) to the number of "pages" the user can scroll to, sideways. Normally, it indicates how many pages there are, and which one we are on, plus it typically provides a way to scroll sideways (by tapping to its left or right).
If I may add to what matt said...
To use a UIPageControl effectively, you also need a UIScrollView that contains the content. An update to the page control should result in a change to the contentOffset of the scrollView as shown in the code below. UIScrollView has a pagingEnabled property that should be set to YES to complete the illusion of paging.
- (IBAction)pageValueChanged:(UIPageControl *)sender
{
// self.pagedView is an IBOutlet to a UIScrollView
[self.pagedView setContentOffset:CGPointMake( sender.currentPage * 320, 0 ) animated:YES];
}

Using interface builder to layout a scrolling view with images and text

I have a requirement in my app to display a bunch of information that includes both text and images. It will be quite long, so it will need to be scrollable to access all the content.
I know that I can achive this by programmatically adding different UILabels, UIImages etc to a UIScrollView. But this is a proof of concept, so I'm looking for something a little quicker than having to work out all the positioning and code required. The information is static anyway, and does not need to interact with code.
Is there a way to do this using the interface builder (storyboard or xib is fine)?
you definitely can do that if you simply want a quick interface
1.> you might need to know how long is your scroll view, for example in my case, i set it to 1568
2.> Then i drag all the controls that will fit for the first 568 pixel view onto the scroll view and position them.
3.> Then change the Y value for that scroll view to something like - 500, so you can see the rest of the scroll view, and put everything you need there.
4.> After you have all your controls, and remember to set the frame back to 0,0,320,568
5.> last step, in your code, set SCROLLVIEW.contentSize = CGSizeMake(320, 1568);
I would still suggestion don't hard code all those values, but if you are looking for a quick way to do your interface, hope that gives you some ideas.
Just start a new project with a single view, it will come with a xib or storyboard for its single ViewController.
Create a UIView by dragging it into the workspace and place as many Labels, Images and UI Elements as you want.
Open the xib / storyboard and drag a UIScrollView in as your root VC's root view. Drag the view containing your layout into the scrollview, making it the scrollviews only subview.
Done (almost)!
If you launch your app at this point, you'll notice you can't scroll. That is because the scrollview is "too stupid" to adjust the size of its contentSize property on its own.
You'll need some code here, but it is only a tiny snippet and you won't need to touch it again:
Create a new Category on UIScrollView.
In your category's implementation, do:
#implementation UIScrollView (MyHandyCategory)
-(void)awakeFromNib {
NSArray *subViews = [self subviews];
UIView *contentView = [subViews objectAtIndex:0];
[self setContentSize:contentView.frame.size];
}
#end
Done (for real this time)! This will check the size of the view your scrollview contains and ajust the contentSize after it has been initialized. You can change the size of your content view as you like, no need to play around with hardcoded values or even Interface Builder values!
If it’s just proof of concept I’d have a WebView and a local HTML page you load. Easy-peasy.
I would suggest UICollectionView. It's fairly straightforward. There's a good tutorial here:
http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12

Can't Wire to Subview in IB

Quick question. Using IB, I have a subview in a ViewController. In that subview I have a label, which I would like to wire to my custom subview class. However, IB will not let me. What am I missing?
I also tried to add the label programmatically; however, it appears that the frame was not ever set. I could hard code the size of the label, but I could not make it dependent on the frame size of my subview, because the frame and the bounds were always zero rects, even after the view showed up in my view controller at a non zero size. Any ideas here would also be much appreciated.
You are actually completely right. It wont let you connect from IB to the Header of a custom view in Xcode 4.6.2
Personally I would file a Radar but I would want to do a bit more research to prove it and as this is a pattern I wouldn't ever use then I won't.
Fortunately you can get around it
Make sure your custom view is configured correctly in IB
and assuming you are setup something like this
Then you can manually declare in your header
#interface MyCustomView : UIView
#property (weak) IBOutlet UILabel *label;
#end
And drag FROM the dot that appears beside the property TO the label.
Or drag FROM the right-click HUD of the custom view TO the label.
Neither case will work by dragging from the label to the view.
In your header file, you need to define the label as an IBOutlet, then you can drag from your file's owner to the label.
IBOutlet * lblSomeLabel;
Disable AutoLayOut and try again.

UIView subview auto resizing

I wrote a little UIView subclass to show a progress HUD. That HUD view works perfect but I faced a little problem in the last days.
In my application I'm presenting a UIViewController in a custom way. When the user selects a row in a tableView I'm creating an instance of my second viewController, move it to the current VC, set it's view's height to zero, add it as subview of the curren VC's view (at the position of the selected cell) and animate the height back to original.
The behaviour looks pretty cool and works great.
But when the second view is added as subview, I'm adding a HUD to this view. When the second view is resizing to the original height, the HUD sticks to the top of the view and is just a few pixels high:
I played around a bit with NSLayoutConstraints... But I didn't get it working until now...
Has someone a good idea on that one? Or does anybody know good and well explained resources on these constraints?
The HUD is actually a background view with the little window as subview. All other elements (the progress view, labels and so on) are subviews of the little window.
In terms of good resources, I definitely recommend WWDC2012's 3 videos: Introduction to Auto Layouts for OSX/iOS, Auto Layout by Example, and Best Practises for Mastering Auto Layout. These have some tips for looking at ambiguity in the layout and dealing with conflicts
Another great reference is Erica Sadun's iOS6 recipe book.
Re your problem. I'm assuming that you're not seeing an error message and you're laying out the progress HUD entirely in the XIB. If so, it sounds like you have two constraints that aren't behaving as you'd like from the xib - the height from the top of the superView and the height of the HUD
Firstly, create an outlet for the constraints to the .h file
#property (strong) IBOutlet NSLayoutConstraint *HUDSuperViewToHUDConstraint;
#property (strong) IBOutlet NSLayoutConstraint *HUDHeight;
Next, in the method in which you open the new viewController with the HUD remove the constraints so that there is no conflict when you first show the new view
[HUDSuperView removeConstraint:self.HUDSuperViewToHUDViewConstraint];
[HUDSuperView removeConstraint:self.HUDHeight];
After you've called [HUDSuperView layoutIfNeeded] for the first time, in the animation or wherever, add the constraints and call layoutIfNeeded again
[HUDSuperView addConstraint:self.HUDSuperViewToHUDViewConstraint];
[HUDSuperView addConstraint:self.HUDHeight];
[HUDSuperView layoutIfNeeded];
If you call these within an animateWithDuration it may even animate the appearance...cheesey
Hope this helps - it's probably more of a step toward the solution rather than the solution itself. Recommend minutes 17 and 53 in the AutoLayout by Example video too.
Steve

Resources