我正在尝试在标签中显示设备的偏航俯仰和滚动。我似乎无法显示值,它只显示数字应该是'...'。这是我的代码,非常感谢任何帮助。
#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>
@interface ViewController (){
}
@property (strong, nonatomic) CMMotionManager *motionManager;
@end
@implementation ViewController
@synthesize motionManager;
@synthesize roll;
@synthesize pitch;
@synthesize yaw;
@synthesize xLabel;
@synthesize yLabel;
@synthesize zLabel;
- (void)viewDidLoad {
[super viewDidLoad];
/** Do any additional setup after loading the view, typically from a nib.
UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
accelerometer.updateInterval = 1.0f/60.0f;
accelerometer.delegate = self;
**/
//motionManager = [[CMMotionManager alloc] init];
//motionManager.deviceMotionUpdateInterval = 1.0 / 60.0;
motionManager = [[CMMotionManager alloc] init];
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(doGyroUpdate) userInfo:nil repeats:YES];
//CMDeviceMotion *deviceMotion = motionManager.deviceMotion;
//CMAttitude *attitude = deviceMotion.attitude;
[motionManager startDeviceMotionUpdates];
}
-(void)doGyroUpdate
{
double x = motionManager.deviceMotion.attitude.roll*180/M_PI;
double y = motionManager.deviceMotion.attitude.pitch*180/M_PI;
double z = motionManager.deviceMotion.attitude.yaw*180/M_PI;
NSString *myString = [NSString stringWithFormat:@"%g", x];
xLabel.text = myString;
myString = [NSString stringWithFormat:@"%f", y];
yLabel.text = myString;
myString = [NSString stringWithFormat:@"%f", z];
zLabel.text = myString;
}
答案 0 :(得分:-1)
...
表示您用于显示文字的UILabel
没有应有的宽度。
尝试在故事板或xib文件中将其扩大。
答案 1 :(得分:-1)
尝试 -
label.numberOfLines = 1;
label.minimumFontSize = 6;
label.adjustsFontSizeToFitWidth = YES;
或者您可以通过storyboard(自动收缩选项)尝试 -
答案 2 :(得分:-2)