如何讀取故事板中創建的UITextView
的x,y位置和寬度?如何讀取故事板中創建的xcode的x,y位置UITextView
在運行時,我需要以編程方式在UITextBox的正下方創建其他對象? 所有運行時創建的對象必須基於故事板UITextView
的位置。
我無法找到答案。而且,我試圖(下圖)的代碼返回0,0
在.H ...
@interface ataglance_central_controller : UIViewController
{
IBOutlet UITextView *transmitter_box;
}
在.M
................. ...
enter code here
#import "ataglance_central_controller.h"
#import <CoreBluetooth/CoreBluetooth.h>
#import <QuartzCore/QuartzCore.h>
#import "TransferService.h"
@interface ataglance_central_controller() <CBCentralManagerDelegate, CBPeripheralDelegate>
{
UITextView* battery_status_textview;
}
@property (strong, nonatomic) IBOutlet UITextView *textview;
@property (strong, nonatomic) CBCentralManager *centralManager;
@property (strong, nonatomic) CBPeripheral *discoveredPeripheral;
@property (strong, nonatomic) NSMutableData *data;
@end
@implementation ataglance_central_controller
-(void)viewDidLoad
{
NSLog(@" ataglance_central_controller.m viewDidLoad. ");
[super viewDidLoad];
NSLog(@" x <<<<<<<<<<<<<<<<<<< b %f", transmitter_box.frame.origin.x);
NSLog(@" y <<<<<<<<<<<<<<<<<<< b %f", transmitter_box.frame.origin.y);
}
-(void)viewDidLayoutSubviews
{
NSLog(@" x viewDidLayoutSubviews %f", transmitter_box.frame.origin.x);
NSLog(@" y viewDidLayoutSubviews %f", transmitter_box.frame.origin.y);
}
日誌
2013-05-21 12:12:10.708 DW x2[447:c07] ataglance_central_controller.m viewDidLoad.
2013-05-21 12:12:10.709 DW x2[447:c07] x <<<<<<<<<<<<<<<<<<< b 0.000000
2013-05-21 12:12:10.709 DW x2[447:c07] y <<<<<<<<<<<<<<<<<<< b 0.000000
2013-05-21 12:12:10.712 DW x2[447:c07] Battery status is unknown.
2013-05-21 12:12:10.743 DW x2[447:c07] x viewDidLayoutSubviews 270.000000
2013-05-21 12:12:10.744 DW x2[447:c07] y viewDidLayoutSubviews 12.000000
完成。現在y是正確的,但x = 270是錯誤的。 ipad storyboard(風景)transmitter_box UITextView實際上是14,12(width = 990 height = 143) –
我通過將聲明從.m移動到.h來解決x = 270的問題。 (我從Apple Dev的BTLE中央/外設傳輸中獲得了原始代碼,在.h和.m文件中都有@interface,這超出了我的透視級別。) –
很酷。我仍然建議使用'NSLayoutConstraint'來指定你編程創建的UIViews相對於UITextView的位置。 –