如何使一个按钮执行多个操作 xcode

How to Make A button do more than one action xcode(如何使一个按钮执行多个操作 xcode)
本文介绍了如何使一个按钮执行多个操作 xcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以在我的 Xcode 项目中,我有一个按钮,我需要两次执行相同的方法,但使用不同的图像请帮助

Ok So In My Xcode project I Have A button That I need to do the same method twice but with A Different Image Plz Help

代码:

UIImage * toImage = [UIImage imageNamed:@"CharacterBackwards.png"];
[UIView transitionWithView:self.view
                  duration:0.01f
                   options:UIViewAnimationOptionTransitionNone
                animations:^{
                    self->Guy.image = toImage;
                } completion:NULL];

sleep(0.4);

推荐答案

这就是方法的用途.创建一个采用图像名称的方法:

This is what methods are for. Create a method that takes an image name:

- (void)transitionToImage:(NSString *)imageName {
    UIImage * toImage = [UIImage imageNamed:@"CharacterBackwards.png"];
    [UIView transitionWithView:self.view
                      duration:0.01f
                       options:UIViewAnimationOptionTransitionNone
                    animations:^{
                        self->Guy.image = toImage;
                    } completion:NULL];
}

现在让您的按钮处理程序调用两次:

Now have your button handler call this twice:

- (IBAction)buttonHandler {
    [self transitionToImage:@"CharacterBackwards.png"];
    [self performSelector:@selector(transitionToImage:) withObject:@"CharacterForwards.png" afterDelay:0.4];
}

这篇关于如何使一个按钮执行多个操作 xcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)