Reputation: 3
Is it possible to make another view appear without the use of a button?
I'm trying to make it so that if the person "CGIntersectsRects" the UIImageView, it would take me to another View Controller.
So basically I am asking if its possible to move between view controllers without the use of a button, and if so, how?
Thanks in advance
Upvotes: 0
Views: 40
Reputation: 266
Always transition from one ViewController to another is accomplished by some code that push or present or perform segue to the destination viewController. The point is when you execute this code. Since you don't use a button you should identify what exactly should trigger the screen change.
What you mean by "I'm trying to make it so that if the person 'CGIntersectsRects' the UIImageView, it would take me to another View Controller" is ambiguous.
If you want to load a screen when the user touches UIImageView, you can still use a button instead of the ImageView and set the appropriate image for that button. Another way is to implement the - (void)touchesBegan: method in your viewController to identify the point where the touch is received and see if the touched point falls inside the imageView frame rect.
Another easy way is to add a gesture recogniser to the UIImageView.
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTouched)];
- (void)imageViewTouched {
//Code to load the new screen
}
If you are trying to load a new screen whenever two views overlap then you have to observe for KVO notification for the frame property of the interested view.
Upvotes: 1
Reputation: 571
Yep, you can do this through a combination of the Storyboard and the implementation UIViewController file.
First, connect your two controllers with a segue in the Storyboard file
Then, click on the segue you've created and set the identifier name. Name is something descriptive like "imageSegue"
Finally, return to your function that is called when the user intersects with the UIImageView and perform the segue
func imageIntersection() {
self.performSegueWithIdentifier("imageSegue", sender: self) //Use the Storyboard identifier name
}
This will cause the current view controller to segue to the view controller that you connected it to in the Storyboard
Upvotes: 0