Iphone 无法更改UIView帧大小
我有一个自定义uiview,我正在尝试更新帧大小。我在一个方法中这样做,一旦单击它。方法被调用,帧值改变,但是在屏幕上什么都没有发生Iphone 无法更改UIView帧大小,iphone,xcode,uiview,frame,cgrect,Iphone,Xcode,Uiview,Frame,Cgrect,我有一个自定义uiview,我正在尝试更新帧大小。我在一个方法中这样做,一旦单击它。方法被调用,帧值改变,但是在屏幕上什么都没有发生 if (!touched) { GameBox *box = (GameBox *)[self.view viewWithTag:40]; [box setFrame:CGRectMake(20, 20, 100, 73)]; NSLog(@"%f", box.frame.origin.x); m
if (!touched) {
GameBox *box = (GameBox *)[self.view viewWithTag:40];
[box setFrame:CGRectMake(20, 20, 100, 73)];
NSLog(@"%f", box.frame.origin.x);
markButton.enabled = NO;
guessButton.enabled = NO;
[self.view reloadInputViews];
NSLog(@"The action bar should now be hidden");
}
else if (touched) {
guessButton.enabled = YES;
markButton.enabled = YES;
[self.view reloadInputViews];
NSLog(@"The action bar should now be visible");
}
[self.view reloadinputview]
通常用于第一响应者。我对您的customview不太了解,但我认为您可以使用以下框架进行设置:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
viewFrame.frame=frame;//Frame Defined by you
[UIView commitAnimations];
如果我查看一下您的自定义视图,可以提供更好的解决方案。您需要在ViewDidDisplay(而不是viewDidLoad)中设置调整帧
显然,这与导航控制器中的表视图有关。我想您已经在
界面生成器中将self.view连接到UIView了
要更改UIView框架,请在界面生成器
中转到文件检查器
,取消选中使用自动布局
,然后在代码中更改框架
希望这能有所帮助。这是因为自动布局,但是您可以在自动布局完成工作或更改其约束后执行。如果您想在自动布局后执行此操作,请添加以下内容
- (void)viewDidAppear:(BOOL)animated {
dispatch_async(dispatch_get_main_queue(), ^{
box.frame = CGRectMake(20, 20, 100, 73)];
});
请询问您想做什么…以便我能理解..我想:a)调整uisubview框的cgrect框架的大小,b)禁用/重新启用猜测按钮和标记按钮我不敢相信我花了3个小时调试…谢谢!这是可行的,但它会影响对整个文档使用自动布局的能力…您只需将translatesAutoResizengMaskintoConstraints设置为YES;在uiView元素上,仍然保留自动布局。这将把元素重绘为新的框架。这对我很有帮助,谢谢,但是你能告诉我为什么你把它放在调度块@DenizIt中,似乎我希望在当前重绘周期后,在viewdideappease方法完成执行后的一段时间,改变框架大小。但我现在不确定。
- (void)viewDidAppear:(BOOL)animated {
dispatch_async(dispatch_get_main_queue(), ^{
box.frame = CGRectMake(20, 20, 100, 73)];
});