在a simple test app for iPhone中,我显示(使用SDWebImage)顶部的用户头像:
当应用用户点击头像时,我想在另一个视图中将该图片显示为“全屏”。
所以我已将该视图添加到我的Xcode 5故事板中,并点击识别器和推送segue,我称之为“pushZoom”(这里是fullscreen):
点击识别器工作正常,我可以看到它的方法被调用。
我的问题:在Interface Builder中可能有一种简单的方法可以将图像传递给新视图,或者我必须采用繁琐的方式(添加ZoomViewContoller。[mh]文件,定义一个图像视图的出口那里)?
以下是我ViewController.m的副本,以防我稍后修改@ GitHub:
#import "ViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>
static NSString* const kAppleMaps = @"https://maps.apple.com/?q=%@";
static NSString* const kGoogleMaps = @"comgooglemaps-x-callback://?q=%@&x-success=myphone://?resume=true&x-source=MyPhone";
static NSString* const kAvatar = @"https://lh6.googleusercontent.com/-6Uce9r3S9D8/AAAAAAAAAAI/AAAAAAAAC5I/ZZo0yzCajig/photo.jpg";
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setTitle:@"Google+"];
_firstName.text = @"Alex";
[_cityBtn setTitle:@"Bochum" forState:UIControlStateNormal];
[_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
placeholderImage:[UIImage imageNamed:@"Male.png"]];
}
- (IBAction)avatarTapped:(id)sender {
NSLog(@"%s", __PRETTY_FUNCTION__);
}
- (IBAction)cityPressed:(id)sender
{
NSURL* testURL = [NSURL URLWithString:@"comgooglemaps-x-callback://"];
NSString* fmt = ([[UIApplication sharedApplication] canOpenURL:testURL] ? kGoogleMaps : kAppleMaps);
NSString* city = [self urlencode:_cityBtn.currentTitle];
NSString* str = [NSString stringWithFormat:fmt, city];
NSLog(@"%s: city=%@ str=%@", __PRETTY_FUNCTION__, city, str);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
- (NSString*)urlencode:(NSString*)str
{
return (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
NULL,
(__bridge CFStringRef) str,
NULL,
CFSTR(":/?@!$&'()*+,;="),
kCFStringEncodingUTF8));
}
@end
答案 0 :(得分:2)
为什么还需要另一个viewController。你可以保留一个完整大小的imageView,最初没有任何图像,并保持隐藏状态,点击该按钮,将其从隐藏中删除。然后传递图像。所以它不需要任何这些问题。这对我来说似乎很简单
答案 1 :(得分:1)
根据我的经验很小,但我表达了自己的想法
- (IBAction)avatarTapped:(id)sender {
//here use your choice in singleton or NSUserdefaults for passing the image url from one VC to another VC. here I used NSUserdefaults
[[NSUserDefaults standardUserDefaults]setObject:kAvatar forKey:@"userimage"];
}
在您的完整图片中显示ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *userimg =[[NSUserDefaults standardUserDefaults]stringForKey:@"userimage"];
[_imageView setImageWithURL:[NSURL URLWithString:userimg]
placeholderImage:[UIImage imageNamed:@"Male.png"]];
}
答案 2 :(得分:0)
将图片网址作为字符串或网址传递到下一个屏幕,并使用
在imageView中显示[self.myImageView setImageWithURL:[NSURL URLWithString:photoURL] placeholderImage:[UIImage imageNamed:@"loading.png"]];
多数民众赞成我会做的。如果你有更好的想法,请在这里发帖。