问题描述
我有一个UIImageView对象,单击该对象将播放动画,我想重用相同的代码来制作多个对象.如何设置发件人标记,以便它知道其不同的对象?
I have a UIImageView object that when clicked it will play a animation, I want to reuse the same code to make multiple objects. How do I set the sender tag so it knows its a different object?
.h
- (IBAction)startClick:(id)sender;
.m
- (IBAction)startClick:(id)sender
{
//UIImageView *theButton = (UIImageView *)sender.tag;
bubble.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed: @"Pop_1.png"],
[UIImage imageNamed: @"Pop_2.png"],
[UIImage imageNamed: @"Pop_3.png"], nil];
[bubble setAnimationRepeatCount:1];
bubble.animationDuration = 1;
[bubble startAnimating];
}
推荐答案
发件人是调用startClick方法的对象.您可以将该对象转换为UIImageView,然后查看该对象的tag属性以确定它是哪个.
The sender is the object that called the startClick method. You can cast that object into a UIImageView and then look at that object's tag property to determine which one it is.
您需要在代码中的其他位置设置tag属性.如果在Interface Builder中具有UIImageViews,则可以使用属性窗口输入标签号.否则,当您分配并初始化UIImageViews时,然后设置tag属性.
You'll need to set the tag property elsewhere in the code. If you have the UIImageViews in Interface Builder, you can use the properties window to enter a tag number. Otherwise, when you allocate and init your UIImageViews, set the tag property then.
这篇关于uibutton发送者标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!