I actually work on a app in Swift.
I have my main ViewController with a ScrollView only.
In my swift file i add 3 view (3 subview controller) into the ScrollView in order to have a special navigation (horizontal navigation like a View Pager).
The problem is that each view has his swift file and therefore i don't find the solution to communicate with the ScrollView of the main ViewController from a subview.
For example a SubViewController (one of the three) have button on it.
And i would put a listener on this button and On click move the position of the screen in the ScrollView (which is on the main view controller), thanks to the method setContentOffset of the scrollview.
You should use delegate or an NSNotificationCenter
In order to pass a notification/delegate to other view in your case UIScrollView.
In you UIScrollView you should implement the delegation methods.
and Whooala, your UIView notified the UIScrollView of something you want it to know.
Here is example of the usage
Delegates in swift?
And here is some documentations
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html
And a tutorial
http://code.tutsplus.com/tutorials/swift-from-scratch-delegation-and-properties--cms-23445
Related
I'm trying to implement the new largeTitleDisplayMode feature in my app. I have a top level mainScrollview that that has multiple childTableViews inside of it. You can swipe left/right(basic page control) inside the mainScrollview to view all the childTableViews. Since all my childTableViews are inside the mainScrollview, the navigation bar's largeTitleDisplayMode functionality does not respond to any of the childTableViews scrolling. Is there a way to to tell the navigationController to respond to a specific scrollView subclass(childTableViews in this case)?
You can try UIScrollViewDelegate scrollViewDidEndDecelerating and calculate which index is on view, so you can update your title. If I understood what you want to do.
I have an iOS application with a subview, as well as a UISegmentedControl. I want to use my UISC to change subview1 to subview2. I decided to drag out a few more ViewControllers onto my storyboard, and put subview1 into the first, and subview2 in the second. After connecting the ViewControllers and making outlets for the subviews, I went back to my main ViewController (at this point there are three) and did
#import "SecondViewController"
SecondViewController *myView;
self.mySubview = myView.myOtherSubview;
but the subview on-screen didn't change. Is my template method of doing this totally wrong? If so, how would you suggest I proceed?
Look at [UIView transitionFromView:toView...]
The basic idea is you'll have to child view controllers (check the docs in UIViewController under the child view controllers section) and transition from the view of one to the view of the other.
https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/clm/UIView/transitionFromView:toView:duration:options:completion:
This question, IOS Storyboard: Load Multiple Subviews for given position, is the same as mine, phrased better. The answer given there worked.
I need to show UIVIew when i will swipeup on UIViewController in ios with animation like it is coming from that UIVIewController,and i need to place that UIVIew in specific portion in UIVIewController not to cover on entire area.But my problem is i need to create this one in storyboard,normally storyboard means its for showing over all project flow so ,how to do that in storyboard.Please help me as soon as possible.I am new to iphone development i can do by programatically but i am not getting how to do with xib.
Thanks & Regards
Harshitha
You're going to want to look at custom View Controller transitions, introduced in iOS 7. There were a couple of WWDC 2013 sessions on this, including one called "Implementing Engaging UI"
The fact that you're using a storyboard doesn't matter, storyboards are just a way to define your view controllers and navigations via segues. If you're doing a custom animation, your View Controller still segues as normal, it just does so with a custom animation (instead of one of the stock ones, like a Navigation Controller "push" or the various Modal VC presentations), which you provide via an animation controller - an object that conforms to UIViewControllerAnimatedTransitioning.
Storyboard, or XIB? They are different.
The simplest thing to do is probably to create your view and get it set up in it's final position inside the view controller. Hook up an outlet to your view in your view controller.
Note the Y coordinate of the view when it is at the location you want it. Then use the size inspector to change the y coordinate of the view to the bottom of the view. (768 for a landscape iPad app, 1024 for a portrait iPad app, etc.)
Then attach a swipe gesture recognizer to your VC's content view, and in action for the swipe gesture, use a UIView animation method (animateWithDuration:animations: or a similar method to move the view's frame.origin.y up to the y desired y coordinate.
I have made a table view using prototype cells on tableviewcontroller from storyboards.
I want a floating button over that uitableview. (button won't scroll with the tableview).
While searching for a solution..I found out that it is possible by adding button to the superview (in that case Uiviewcontroller subclasses Uitableview).
Can any one tell me how to do that using storyboards??
I think best thing you have to do is to create a UIViewController and add it a UITableView. Then you can add also the UIButton you want to the view controller's view. Don't forget to set the view controller to be the delegate and data source for your table view, and to add <UITableViewDataSource,UITableViewDelegate> to your view controller interface.
If you must do it using Storyboards and not in code, then you need to use a UIViewController and not a UITableViewController.
Add the UITableView and make it full screen - link up its Delegate and DataSource to the UIViewController and adhere to the two protocols in the .h file of your UIViewController.
When adding the button, drag it into the view hierarchy in the "Document Outline" sidebar, and not by dragging it onto the UITableView. Be careful if you're ever dragging the button around the view because if you drag and drop it on top of the UITableView then it will become a subview of the UITableView. If you want to move it around you'll need to select it and then use the arrow keys.
Anyway, apart from that it should all be very easy - add your constraints to keep it in the right place and you should be able to use the button as normal.
I have a singleton instance of a custom UIView with a method -(void)display whose job is to animate the custom view in and out on whatever screen is currently being displayed. (kind of like the -show method in UIAlertView).
My question is how do I determine which view is at the top of the UIView hierarchy and currently displayed?
The "top" of the view hierarchy is a UIWindow. And there can be (and usually is) more than one UIWindow in the application. If you want to have something shown over everything else on the screen, I suggest you implement a custom UIWindow. E.g. UIAlertView is also implemented this way.