当点击它时,是否可以让UIImage
导航到另一个ViewController
?
就像UIButton
。
感谢。
答案 0 :(得分:3)
你可以使用
var tap = UITapGestureRecognizer(target: self, action: Selector("imageCliecked"))
yourimageView.addGestureRecognizer(tap)
yourimageView.userInteractionEnabled = true // this is must dont forget to add
方法是
func imageCliecked()
{
println("Tapped on Image")
// navigate to another
self.performSegueWithIdentifier("yoursegueName", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?)
{
if segue.identifier == "yoursegueName" {
var destViewController: ViewController = segue.destinationViewController as ViewController
destViewController.img = imageView.image // pass your imageview
}
}
另一个ViewController
class ViewController: UIViewController
{
strong var img: UIImage!
override function viewDidLoad()
{
if(self.img)
self.imageView.image = img;
}
}
答案 1 :(得分:0)
"abcdefg".length - "bcdefg".length
= 7 - 6
= 1
答案 2 :(得分:0)
对于你的问题,我尝试了以下解决方案。也正常。
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var tapGesture = UITapGestureRecognizer(target: self, action: "navigationFromImage:")
tapGesture.numberOfTapsRequired = 1
imageviewNavigation.userInteractionEnabled = true
imageviewNavigation.addGestureRecognizer(tapGesture)
}
func navigationFromImage(sender: UIGestureRecognizer)
{
var secondViewController = storyboard?.instantiateViewControllerWithIdentifier("navigatingSecondViewController") as SecondViewController
secondViewController.globalImage = imageviewNavigation.image!
navigationController?.pushViewController(secondViewController, animated: true)
//OR
presentViewController(secondViewController, animated: true, completion: nil)
}
同样在Storyboard中,单击所需的视图控制器
1.Go to or click show the Identity inspector
2.Click Identity
3.In StorybordId you must give "navigatingSecondViewController" or whatever you want.
4.Finally you must give same name in your storyboard?.instantiateViewControllerWithIdentifier("navigatingSecondViewController")
在SecondViewController中
var globalImage: UIImage = UIImage()
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view.
imageAccess.image = globalImage
}
答案 3 :(得分:-2)
是的,可以使用属性......将一个控制器导航到另一个控制器......
e.g。
// second Controller.....(you pass image on this controller)
#import <UIKit/UIKit.h>
@interface NewScreen : UITableViewController
{
}
@property(strong,nonatomic)UIImage *yourImage;
@end
/// First Controller where you pass your image...
- (IBAction)convertVideoButtonClicked:(id)sender
{
NewScreen *objNew=[self.storyboard instantiateViewControllerWithIdentifier:@"NewScreen"];
objNew.yourImage=imageNamed;
[self.navigationController pushViewController:objNew animated:YES];
// NSURL *videoPath = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"part1" ofType:@"mov"]];
// [self convertVideoToMP4:videoPath];
}