Objective c 更新按钮';当设备旋转时,以编程方式调整其位置

Objective c 更新按钮';当设备旋转时,以编程方式调整其位置,objective-c,ios5,uibutton,Objective C,Ios5,Uibutton,我是iOS开发的新手,这是我的第一个问题。如果这是一个愚蠢的问题,我很抱歉 我没有使用XIB。我的目标是在设备旋转时按下按钮并移动其位置。我的问题是,在旋转发生后,我找不到更新/刷新屏幕上按钮“框架”的方法 这是我正在使用的04个文件。我已经阅读了其他几个SO问题,但我无法解决此问题。谢谢大家的建议 LV_AppDelegate.h #import <UIKit/UIKit.h> // @class LV_ViewController; // @interface LV_AppDel

我是iOS开发的新手,这是我的第一个问题。如果这是一个愚蠢的问题,我很抱歉

我没有使用XIB。我的目标是在设备旋转时按下按钮并移动其位置。我的问题是,在旋转发生后,我找不到更新/刷新屏幕上按钮“框架”的方法

这是我正在使用的04个文件。我已经阅读了其他几个SO问题,但我无法解决此问题。谢谢大家的建议

LV_AppDelegate.h

#import <UIKit/UIKit.h>
//
@class LV_ViewController;
//
@interface LV_AppDelegate : UIResponder <UIApplicationDelegate>
//
@property (strong, nonatomic) UIWindow *window;
//
@property (strong, nonatomic) LV_ViewController *viewController;
//
@end
LV_ViewController.h

#import <UIKit/UIKit.h>
//
@interface LV_ViewController : UIViewController {
    UIButton *button_Narr_Places;
}
//
@property (nonatomic, retain) UIButton *button_Narr_Places;
//
@end

LV_ViewController.m-loadView
函数中,为按钮声明(本地)变量,如下所示:

UIButton *button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];
这将创建按钮的临时本地副本(该副本“隐藏”全局属性,因此您无法在此函数中访问它),然后在函数末尾将其丢弃。如果希望以后能够引用它(如在
WillAnimateRotationInterfaceOrientation
中),则需要使用头文件中定义的属性:

button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];
或者更好:

self.button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];

请注意,除非您另有原因,否则您应该使用
self.
符号通过ivar的访问器而不是直接访问ivar。

谢谢。您的建议解决了我的问题,并且消除了一堆{button_Narr_Places'的本地声明隐藏实例变量。}警告消息。
button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];