UIButton - 框架和界限零 - 基于页面的应用程序

时间:2013-05-14 16:46:31

标签: iphone ios objective-c cocoa-touch storyboard

有一个类似但尚未解决的问题 bound and frame for a UIButton

我正在使用自动布局的故事板和“基于页面的应用程序模板

我能够通过使基于标准页面的应用程序向故事板添加按钮并在其中引用它来重现此问题

DataViewController.m

viewDidAppear

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"View did appear");
    NSLog(@"self.myButton.bounds = %@",NSStringFromCGRect(self.myButton.bounds));
    NSLog(@"self.myButton.frame = %@",NSStringFromCGRect(self.myButton.frame));
    NSLog(@"self.myButton = %@",self.myButton);
}

输出
2013-05-14 19:37:45.954 FrameTest4 [10777:c07] View确实出现了 2013-05-14 19:37:45.966 FrameTest4 [10777:c07] self.myButton.bounds = {{0,0},{0,0}} 2013-05-14 19:37:45.968 FrameTest4 [10777:c07] self.myButton.frame = {{0,0},{0,0}} 2013-05-14 19:37:45.970 FrameTest4 [10777:c07] self.myButton =>

标题文件

#import <UIKit/UIKit.h>    
@interface DataViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *dataLabel;
@property (strong, nonatomic) id dataObject;
@property (weak, nonatomic) IBOutlet UIButton *myButton;

当我使用单个视图应用程序使用自动布局和故事板运行相同的代码时,它可以正常工作。

我需要这些信息的原因是我需要运行一个以按钮结束的动画。 谢谢 莱恩

1 个答案:

答案 0 :(得分:1)

我通常在新的iOS 5方法viewDidLayoutSubviews中执行此类操作。

但要小心,因为这种方法可能不仅仅被称为一次,所以你可能需要保持一个标志来跟踪它。

相关问题