【发布时间】:2014-03-27 09:32:45
【问题描述】:
我想触摸 UIImageView 并使用导航视图在另一个视图中以全尺寸显示该图像。与手机中的画廊相同。 只是以编程方式创建演示。因为我是 iphone 开发的新手。
这是我的代码。
- (void)viewDidLoad
{
NSLog(@"Enter in viewDidLoad method");
UIScrollView * scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
scroll.contentSize = CGSizeMake(320, self.view.frame.size.height+50);
[self.view setUserInteractionEnabled:YES];
[scroll setUserInteractionEnabled:YES];
[self.view addSubview:scroll];
int x=5;
int y=5;
int hei=100;
int wid=100;
int k=1;
for (int i=0; i<3; i++)
{
for(int j=0;j<50;j++)
{
imageView = [[UIImageView alloc]initWithFrame:CGRectMake((x+wid)*i+5, (y+hei)*j+5, wid, hei)];
[imageView setImage:[UIImage imageNamed:@"Motocross.png"]];
[imageView setUserInteractionEnabled:YES];
scroll.contentSize = CGSizeMake(320,(y+hei)*j+hei*2);
[imageView setTag:k];
[scroll addSubview:imageView];
NSLog(@"The tag is == %d",k++);
NSLog(@" (%d,%d)x == %d",i,j,(x+wid)*i+5);
NSLog(@" (%d,%d)y == %d",i,j,(y+hei)*j+5);
}
}
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"Exit from viewDidLoad method");
}
//Navigate on touch the imageView.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Enter in touchesBeganWithEvent method");
UITouch *touch = [touches anyObject];
if ([touch view] == imageView)
{
NSLog(@"Enter in if condition of touch");
DetailViewController *detailViewController = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
detailViewController.imageD = imageView.image;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
NSLog(@"Exit from if condition of touch");
}
NSLog(@"Exit from touchesBeganWithEvent method");
}
我想点击 imageView 并且视图将导航到 detailViewController 并以大尺寸显示该图像。但是当我点击 imageView 时没有调用这个 touchesBegan 方法。在这我不是创建 UIImageView 数组只是在循环中分配 init .. 谢谢!
【问题讨论】:
-
是否调用了 touchesBegan 方法?您是否尝试在方法中插入断点?
-
@我想你的检查不正确试试这个:if([touch.view isKindOfClass:[UIImageView class]])
标签: ios uiimageview uitouch touchesbegan