iphone - 获取图像索引
<p><p>我正在开发一个应用程序,其中我有 15 个图像存储在一个数组中作为正面图像,另外 15 个图像作为背面图像。我想将该图像垂直添加到 ScrollView 中,我已经成功完成了,但现在我的问题是如何比较这两个数组图像。</p>
<p>在垂直 ScrollView 上添加正面图像已成功添加但不是随机打乱,即当我双击正面图像时,会显示背面阵列图像,但该 ImageView 中仍存在正面图像。</p>
<p>请帮我解决这个问题。</p>
<p>提前致谢。 </p>
<p><b>请检查我的代码:</b> </p>
<pre><code>- (void)viewDidLoad
{
;
AppDelegate * delegate=(AppDelegate *)[delegate];
delegate.front=TRUE;
delegate.back=FALSE;
UIScrollView *scrollView=[initWithFrame:CGRectMake(0, 0, 320, 480)];
;
;
FrontsCards=[initWithObjects:@"cloub1.png",@"cloub2.png",@"cloub3.png",@"cloub4.png",@"cloub5.png",@"cloub6.png",@"cloub7.png",@"cloub8.png",@"cloub9.png",@"cloub10.png",@"cloub11.png",@"cloub12.png",@"diamond1.png",@"diamond2.png",@"diamond3.png",@"diamond4.png",@"diamond5.png", nil];
for(int m=0; m<;m++)
{
ImgView.tag=m;
int randIdx=arc4random()%;
NSString *imageName=;
//NSLog(@"%d",randIdx);
NSString *fullImageName=;
int padding=25;
// padding is given.
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[initWithFrame:imageViewFrame];
];
;
;
UITapGestureRecognizer *doubleTap = [ initWithTarget:self action:@selector(doubleTapImgView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
;
self.ImgView.userInteractionEnabled=YES;
}
CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*, scrollView.frame.size.height);
;
;
}
- (void)doubleTapImgView:(UITapGestureRecognizer *)gesture
{
AppDelegate * delegate=(AppDelegate *)[delegate];
delegate.back=TRUE;
delegate.front=FALSE;
NSLog(@"%d", gesture.view.tag);
NSLog(@"double-tap");
BackCards =[initWithObjects:@"card1.jpg",@"card2.jpg",@"card3.jpg",@"card4.jpg", nil];
UIScrollView *scrollView=[initWithFrame:CGRectMake(0, 0, 320, 480)];
;
;
for(int m=0; m< ;m++)
{
NSString *imageName=;
NSString *fullImageName=;
int padding=25;
// padding is given.
CGRect imageViewFrame=CGRectMake(scrollView.frame.size.width*m+padding, scrollView.frame.origin.y, scrollView.frame.size.width-2*padding, scrollView.frame.size.height);
ImgView=[initWithFrame:imageViewFrame];
];
;
;
UITapGestureRecognizer *doubleTap = [ initWithTarget:self action:@selector(doubleTapImgView:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
;
self.ImgView.userInteractionEnabled=YES;
}
CGSize scrollViewSize=CGSizeMake(scrollView.frame.size.width*, scrollView.frame.size.height);
;
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>为了实现这一点,您可以为每个图像设置 <code>Tag</code> 值,当您点击该特定图像时,您将获得标签值并使用该 <code>tag</code> 值。</p>
<pre><code>self.imagview.tag=Unique_tagValue;
</code></pre>
<p>单击该图像时,您可以从另一个阵列设置图像。</p>
<pre><code>self.imageview.image=];
</code></pre>
<p>编辑:-</p>
<p>在 <code>viewDidLoad</code> 方法中为 imageview 设置标签,像这样 <code>ImgView.tag=m+100;</code></p>
<p>在<code>doubleTapImgView</code>方法中保留以下代码</p>
<pre><code> for(int m=0; m< ;m++)
{
UIImageView *imgview=(UIImageView *);
imgview.image=];
}
</code></pre>
<p> subview 翻译:-</p>
<pre><code> ;
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 获取图像索引,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/16557466/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/16557466/
</a>
</p>
页:
[1]