2013-05-14 72 views
0

有一个类似的,但悬而未决的问题 bound and frame for a UIButton的UIButton - 框架和边界零 - 页基于应用程序

我使用带有自动布局和故事板“页基于应用程序模板

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

viewDidAppear DataViewController.m

- (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年5月14日19:37:45.954 FrameTest4 [10777:C07]查看确实出现 2013年5月14日19:37:45.966 FrameTest4 [10777:C07]自我。 myButton.bounds = {{0,0},{0,0}} self.myButton.frame = {{0,0},{0,0,0}} 2013-05-14 19:37:45.968 FrameTest4 [10777:c07] 0}} 2013年5月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; 

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

我需要这些信息的原因是我需要运行结束于按钮的动画。 谢谢 Ryan

+0

从您的日志中不清楚:您的按钮是否为零? – Mundi 2013-05-14 19:51:19

+0

按钮不是零,只是框架和边界。 – 2013-05-15 05:40:54

回答

1

我通常在新的iOS 5方法viewDidLayoutSubviews做这种事情。

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

+0

谢谢 - 我曾尝试过这种方法,但它也没有奏效。我有一种感觉,我可能不得不使用禁忌 – 2013-05-15 08:12:33

+0

我昨天尝试过,它没有工作,并今天再次尝试,现在它似乎有价值。回答接受谢谢。 – 2013-05-15 10:34:58