I have a StoryBoard and a base ViewController include some images.
How I can touch an image of them to go to other ViewController linked that UIImageView by modal?
create the new viewController
drag a tap gesture recognizer to the first viewController
right click + drag from the gesture recognizer to the new viewController and you will see the option modal
right click + drag from the UIImageView to the gestureRecognizer and you will see the gestureRecognizer option select it and that's all
Make sure the UIImageView have the "User Iteraction Enabled" option ckecked
just added a sample project to my github
You can try the following to move from one view controller to another:
[MyImageView.view removeFromSuperview];
[MyNewViewController.view addSubview:MyImageView.view];
If you wish to animate that change making it fly its way, you might need to create animation for MyImageView.view.frame from the old to the new view controller. For that you'll need to use methods like
CGRect fromFrame = [MyImageView.view convertRect:MyImageView.view.frame toView:MyOldViewController]
How about using buttons instead of images?
http://www.cocoanetics.com/2010/02/uiimageview-touch-handling-uibutton/
Related
I am trying to make some kind of popup view when a button i pressed on the iPhone. And it would be nice if I could manage that popup view with a ViewController. I have found out that the UIPopoverController could have been the solution, but it seems that it only works on the iPad...
But anyway, are there any similar solutions for the iPhone?
I am using storyboard
Check out these repos on Github:
https://github.com/werner77/WEPopover
https://github.com/50pixels/FPPopover
Create a separate view controller and resize its xib file and make it look like a popup.
Then ADD this view controller as a subview, and also add it as childController too.
[self addChildViewController:self.popOverViewController];
[self.view addSubview:self.popOverViewController.view];
Now Make it hidden initially.
self.popOverViewController.view.hidden = YES;
If a user taps on Button then using fade in & Fade out animation you can hide/unhide it.
I can tell you how to fade in and fade out if you want to know it further, I hope you can do it easily.
In interface builder make a UIView size of the screen and then make another in that Uiview with the style, size and the such for your pop over. Make its class, hook everything together.
CustomPopUpView *view = [[CustomPopUpView alloc] initWithFrame.....]
Add this all to your UIViewController with
[self.view addsubview:view]
Then attach a tapGestureRecognizer to the back view that animates the whole view off screen when tapped. So now if they click off your pop over view it close it will animates it off screen.
Hope this makes sense.
BooRanger
I have a view based Window, on the view I added single tap UIGestureRecognizer. I then added a new popover type view, which let's name "Popover view", on this view with a `UIButton' on it.
So now when I click on UIButton, it calls the single tap UIGestureRecognizer action, but I want it to go into UIButton method.
Basically, the structure is:
UIViewCintroller.view + single tap UIGestureRecognizer ---> on top added (A "Popover View" + UIButton on it).
Now I want it to do something when the UIButton is clicked, and the single tap UIGestureRecognizer.
But it is only calling the single tap UIGestureRecognizer method.
Thanks.
I'm now working with view-based application. It's just simple. If I touch the view, the view flips using animation ability of UIView. This is all.
What I want to do after this...is...locating a kind of button in the middle of the main view. BUT!, the button must not be animated while the main view is flipping.
How do I do this?
I dont know this is a correct way or not and i havnt tried this. Just a thought.
Create a UIButton in appdelegate and add that button as subview to the UIWindow.
So you can access that button in anyview and so that you can keep that button in the front and change view controllers.
I saw this amazing transition in an app: when the user clicks on an item in the tableview and it "drills down" the transition is done "on top" of a background. That is the background image is static and just the actual tableview and whatever is presented after pressing something is moving (from right to left as usual).
How is this layered tableview transition done? Anyone knows?
(the app is "Munch-5-a-day" in the info-view)
Endemic gives you the right direction. Another way can be view controllers with transparent background and then customize UIWindow.
UINavigationController is a subclass of the standard UIViewController class, so it inherits the view property of UIViewController. I would imagine that the background image transition consists of two important steps:
Assign a UIImageView containing the desired background image to the view property of the NavController
Set self.view.backgroundColor = [UIColor clearColor] in each ViewController, most likely in the viewDidLoad method.
I'm currently unable to test this, but it should work.
Reference: UINavigationController Class Reference
How would I go about implementing dragging and dropping a UIView from UIPopoverController into the back UIView.
This is the functionality that Pages provide in their insert media popover, where you can drag a shape out from the UIPopoverController and drop it into the main document.
I am actually confused with the pan UIGestureRecognizers and where they will be implemented.
Thanks,
Umer
According to the documentation on UIPopoverController, when the popover is presented, it is presented on a special "window". Because of this, simply adding a subview to the popover view controller's content view controller is not sufficient to be able to drag a view outside of the popover view controller's view.
The easiest solution here is to create your own window, add your drag-able view to the window when dragging occurs. Make the window visible for the duration of the drag/drop, and then release your window when complete.
As mentioned above, gesture recognizers (GR) are best suited for Drag/Drop functionality. Once the GR's state has changed to "Began" the GR will control all touches until the "Ended" or "Cancelled" state is achieved which makes it ideal for dragging views between view controllers as well as windows :)
Example:
#interface MySplitViewController : UISplitViewController {
UIView *dragView;
UIWindow *dragWindow;
}
Implementation:
NOTE we do not need to call "makeKeyAndVisible" on our window. We just need to set its "Hidden" property
From Apple in regards to the makeKeyAndVisible method:
// convenience. most apps call this to show the main window and also make it key. otherwise use view hidden property
-(void)dragBegan{
self.dragWindow = [[UIWindow alloc] initWithFrame:self.view.window.frame];
[self.dragWindow addSubview:self.dragView];
[self.dragWindow setHidden:NO];
}
Here we handle the Gesture Recognizer's "Ended" or "Cancelled" state.
NOTE: It is important to remove the window when the Drag/Drop is complete or you will lose user interactiveness with the views below.
-(void)dragEnded{
[self.dragView removeFromSuperview];
[self.dragWindow setHidden:YES];
[self.dragWindow release];
[self.view addSubview:self.dragView];
}
You have to deal with two view controllers one that's in the background called mainController one that presented using a UIPopoverViewController called popoverController. Your popoverController could add a UIPanGestureRecognizer to the views, that the user can drag. The action target of the gestureRecognizer could be a method on the popoverController.
Once the user starts a dragging operation your action method is called with the gestureRecognizer as an argument, were the state of the gestureRecognizer is UIGestureRecognizerStateBegan. You could than save the current frame of the view somewere to be able to animate it back, when the dropping fails. It might be necessary to move the view to an other superview (the window for example), because I'm not sure if UIPopoverViewController clipsToBounds its view.
As the user draggs, your action method is called over and over with the gestureRecognizer in the state UIGestureRecognizerStateChanged. Use the translationInView: method on UIPanGestureRecognizer to determine how much the user dragged and update the dragged views center/frame/transform accordingly.
Once the user lifts his finger the action method is called for a last time with the gestureRecoginzers state set to UIGestureRecognizerStateEnded. Now it's time to find out if the drag was successful. For example the popoverController could ask the mainController via delegation if there's a drop target under the views current position, if so the mainController can take action, else the popoverController would animate the dragged view back to were it came from, and add it back as a subview to it's view.
I hope this is somehow comprehensible and helpful.