Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何以编程方式移动UIButton。目标C-Xcode_Ios_Objective C_Xcode_Uibutton - Fatal编程技术网

Ios 如何以编程方式移动UIButton。目标C-Xcode

Ios 如何以编程方式移动UIButton。目标C-Xcode,ios,objective-c,xcode,uibutton,Ios,Objective C,Xcode,Uibutton,我看到了一些解决方案,但没有一个能解决我的问题 我有一个ui按钮,只需将其拖放到脚本编辑器中的UIViewController中即可创建 ui按钮有一个出口链接到与该视图关联的ui视图控制器的.h文件。它也在.m文件中合成 @property (strong, nonatomic) IBOutlet UIButton *answerButton; 我想在运行时像这样更改按钮的位置 CGRect btFrame = answerButton.frame; btFrame.origin.x = x

我看到了一些解决方案,但没有一个能解决我的问题

我有一个
ui按钮
,只需将其拖放到脚本编辑器中的
UIViewController
中即可创建

ui按钮
有一个出口链接到与该视图关联的
ui视图控制器
的.h文件。它也在
.m
文件中合成

@property (strong, nonatomic) IBOutlet UIButton *answerButton;
我想在运行时像这样更改按钮的位置

CGRect btFrame = answerButton.frame;
btFrame.origin.x = xOne;
btFrame.origin.y = yOne;
answerButton.frame = btFrame;
然而,每当我尝试这个,按钮拒绝移动


所有其他编辑功能(如
setTitle
等)都正常工作,但由于某些原因,框架无法按我所希望的方式移动。

用下面的代码替换您的代码,其中包括删除自动调整大小掩码的代码

CGRect btFrame = answerButton.frame;
btFrame.origin.x = xOne;
btFrame.origin.y = yOne;
answerButton.autoresizingMask = UIViewAutoresizingNone;
answerButton.frame = btFrame;
.h文件

    #import <UIKit/UIKit.h>

@interface ViewController : UIViewController{
    IBOutlet UIButton *theButton;
}
@property(nonatomic, strong) IBOutlet UIButton *theButton;
-(IBAction)moveTheButton:(id)sender;

@end
}


此代码将按钮从一个点移动到另一个点。

只需取消选中文件检查器中的“使用自动布局”即可。

使用手势功能是否使用自动布局?@Vikas,用户没有移动按钮。按钮的位置由它们之前所做的一些选择决定。xOne,yOne是两个int值,创建一个点,该点根据之前所做的选择而更改。我只想将frame设置为这些已知的int值。@SamBo请确保您的故事板中没有启用自动布局。如果你需要帮助确定它是否已启用并关闭。成功!非常感谢Rob&Zaphod!你有没有把xOne,yOne记录下来,看看是什么?
-(IBAction)moveTheButton:(id)sender{
CGRect btFrame = theButton.frame;
btFrame.origin.x = 90;
btFrame.origin.y = 150;
theButton.frame = btFrame;