简体   繁体   English

iOS:如何从另一个视图控制器类更改视图大小/来源?

[英]iOS:How do you change a view size/origin from another view controller class?

I have two views(Storyboard scenes) on screen but I want to change the size/origin of " View A " from " View B ". 我在屏幕上有两个视图(Storyboard场景),但我想从“ View B ”更改“ View A ”的size/origin But my below code is not working, the view remains the same: 但是我下面的代码不起作用, view保持不变:

Code added to viewDidLoad from " View B " 代码从“ View B ”添加到viewDidLoad

ViewA *viewA = [[ViewA alloc]init];
 viewA.view.frame = CGRectMake(0,100,200,2000);

If someone could please help I would be thankful :) 如果有人可以帮助我,我将非常感激:)

I want to change the size/origin of "View A" from "View B" 我想从“视图B”更改“视图A”的大小/来源

What's the relationship between the views? 视图之间有什么关系? If the two views are managed by different view controllers, then they shouldn't talk to each other directly. 如果两个视图由不同的视图控制器管理,则它们不应直接相互通信。 Generally, a view that might have something to communicate to the rest of the world calls a method on its delegate, which is typically the view controller that manages it. 通常,可能需要与世界其他地方进行通信的视图在其委托上调用一个方法,该方法通常是管理它的视图控制器。 That view controller would then take appropriate action -- update the data model, send a message to another view controller, post a notification, etc. The only object that should mess directly with a given view graph is the view controller for that graph. 然后,该视图控制器将采取适当的措施-更新数据模型,向另一个视图控制器发送消息,发布通知等。唯一应直接与给定视图图混淆的对象是该图的视图控制器。

There might be not enough details to give a good answer however assuming those views are part of the same view controller you would likely want to connect an action from viewA to your controller which would change viewB's frame. 可能没有足够的细节来给出良好的答案,但是假设这些视图是同一视图控制器的一部分,您可能希望将动作从viewA连接到控制器,这将改变viewB的框架。

Assuming these views have separate controllers whose parent is the AppDelegate you will want to forward that message to the parent and handle it from there. 假设这些视图具有单独的控制器,其父对象为AppDelegate,您将需要将该消息转发给父对象并从那里处理它。

If the action supposed to influence multiple behaviors in many controllers then you may also want to consider NSNotificationCenter route. 如果该动作应该影响许多控制器中的多种行为,那么您可能还需要考虑NSNotificationCenter路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS - 如何控制模态视图控制器的大小? - iOS — how do you control the size of a modal view controller? 如何将ID从具有地图视图的视图控制器传递到另一个视图控制器? - How do you pass id from a view controller with a map view to another view controller? 如何从iOS中的另一个类调用视图控制器方法? - How do I call a view controller method from another class in iOS? 如何更改为另一个视图控制器 - How do I change to another view controller 如何在Xamarin iOS Storyboard中使子视图大小适合视图控制器? - How do you make a subview size to fit a view controller in a Xamarin iOS storyboard? 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS? iOS:如何从另一个视图控制器调用根控制器 - iOS: How to call root controller from another view controller 在iOS 5 Storyboard中,如何从Popover将新场景推送到原始视图控制器? - In an iOS 5 Storyboard, how do you push a new scene to the original view controller from a Popover? 你如何在 Swift 中检查当前的视图控制器类? - How do you check current view controller class in Swift? 在容器视图中的视图控制器中,如何访问包含容器的视图控制器? - From within a view controller in a container view, how do you access the view controller containing the container?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM