当我点击图像时,它在 iphone 5 秒后无法正常工作
When I tap on a image its not working properly from iphone 5s
I added an image to a button. I am using gestures for animating the image in my sample app. It was working fine with iPhone 4, 4s, and 5 but the problem arise from iphone 5s.
` -(void)awakeFromNib
{
[super awakeFromNib];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(characterImagedTapped)];
self.characterImageView.userInteractionEnabled = YES;
[self.characterImageView addGestureRecognizer:tapGestureRecognizer];
}
这里是characterImagedTapped函数,
' -(void) characterImagedTapped
{
如果 ([self.delegate respondsToSelector:@selector(didCharacterTapped:)])
[self.delegate performSelector:@selector(didCharacterTapped:)];
} ' 这个函数正在调用 didCharacterTapped.
When I tapped on the button it will call didCharacterTapped function it's implementation as below:
-(void)didCharacterTapped:(BOOL)tapped
{
if (tapped && !isCharacterAnimating) {
[self startWelcomeBackCharacterAnimation];
}
}`
如果点击值为 YES,它将调用 startWelcomeBackCharacterAnimation。如果为 NO,它将跳过并且图像将不会动画化。
实际上当我点击按钮时,点击的布尔值应该是 YES,但是点击的布尔值在 iPhone 5s 版本中总是显示 NO。
根据您的评论,我可以看到您正在将 tapGestureRecognizer
设置为特定的 imageview
,即 self.characterImageView
.
尝试将其分配给 characterImageView
的 parentview
。
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(characterImagedTapped)];
[self.characterImageView setUserInteractionEnabled:YES];
[self.view addGestureRecognizer:tapGestureRecognizer];
-(void) characterImagedTapped
{
if ([self.delegate respondsToSelector:@selector(didCharacterTapped:)]) {
[self.delegate performSelector:@selector(didCharacterTapped:) withObject:[NSNumber numberWithBool:YES]];
}
else {
[self.delegate performSelector:@selector(didCharacterTapped:) withObject:[NSNumber numberWithBool:NO]];
}
}
-(void)didCharacterTapped:(NSNumber *)tapped
{
if (tapped.boolValue) {
//[self startWelcomeBackCharacterAnimation];
}
else {
}
}
您可以使用对象执行选择器,并且在选择器中您可以按照上述代码访问对象值
I added an image to a button. I am using gestures for animating the image in my sample app. It was working fine with iPhone 4, 4s, and 5 but the problem arise from iphone 5s.
` -(void)awakeFromNib
{
[super awakeFromNib];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(characterImagedTapped)];
self.characterImageView.userInteractionEnabled = YES;
[self.characterImageView addGestureRecognizer:tapGestureRecognizer];
}
这里是characterImagedTapped函数,
' -(void) characterImagedTapped { 如果 ([self.delegate respondsToSelector:@selector(didCharacterTapped:)]) [self.delegate performSelector:@selector(didCharacterTapped:)]; } ' 这个函数正在调用 didCharacterTapped.
When I tapped on the button it will call didCharacterTapped function it's implementation as below:
-(void)didCharacterTapped:(BOOL)tapped
{
if (tapped && !isCharacterAnimating) {
[self startWelcomeBackCharacterAnimation];
}
}`
如果点击值为 YES,它将调用 startWelcomeBackCharacterAnimation。如果为 NO,它将跳过并且图像将不会动画化。
实际上当我点击按钮时,点击的布尔值应该是 YES,但是点击的布尔值在 iPhone 5s 版本中总是显示 NO。
根据您的评论,我可以看到您正在将 tapGestureRecognizer
设置为特定的 imageview
,即 self.characterImageView
.
尝试将其分配给 characterImageView
的 parentview
。
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(characterImagedTapped)];
[self.characterImageView setUserInteractionEnabled:YES];
[self.view addGestureRecognizer:tapGestureRecognizer];
-(void) characterImagedTapped
{
if ([self.delegate respondsToSelector:@selector(didCharacterTapped:)]) {
[self.delegate performSelector:@selector(didCharacterTapped:) withObject:[NSNumber numberWithBool:YES]];
}
else {
[self.delegate performSelector:@selector(didCharacterTapped:) withObject:[NSNumber numberWithBool:NO]];
}
}
-(void)didCharacterTapped:(NSNumber *)tapped
{
if (tapped.boolValue) {
//[self startWelcomeBackCharacterAnimation];
}
else {
}
}
您可以使用对象执行选择器,并且在选择器中您可以按照上述代码访问对象值