我有一个视图控制器,可以创建一个图像框(白框),用户可以在其中签名。在ipad上的纵向模式下,这很好用但是当我从横向模式进行签名时,框出现在屏幕的左下方,而不是像它应该的那样位于中心。
我已经使用了以下代码,我们将不胜感激任何帮助或建议。
@interface PropertyOwnerSignatureViewController ()
@end
@implementation PropertyOwnerSignatureViewController
@synthesize mySignatureImage;
@synthesize lastContactPoint1, lastContactPoint2, currentPoint;
@synthesize imageFrame;
@synthesize fingerMoved;
@synthesize navbarHeight;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
// //set the title of the navigation view
[self.navigationItem setTitle:@"Sign here"];
self.view.backgroundColor = [UIColor lightGrayColor];
//get reference to the navigation frame to calculate navigation bar height
CGRect navigationframe = [[self.navigationController navigationBar] frame];
navbarHeight = navigationframe.size.height;
//
// //create a frame for our signature capture based on whats remaining
imageFrame = CGRectMake(self.view.center.x,
self.view.center.y,
self.view.frame.size.width,
self.view.frame.size.height/2.5);
// //allocate an image view and add to the main view
mySignatureImage = [[UIImageView alloc] initWithImage:nil];
mySignatureImage.frame = imageFrame;
mySignatureImage.center = self.view.center;
mySignatureImage.backgroundColor = [UIColor whiteColor];
[self.view addSubview:mySignatureImage];
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
if(appDelegate.imagePhSignature)
{
mySignatureImage.image = appDelegate.imagePhSignature;
}
}
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
mySignatureImage.center = self.view.center;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
/* start special animation */
break;
case UIDeviceOrientationPortraitUpsideDown:
/* start special animation */
break;
default:
break;
};
}
答案 0 :(得分:0)
替换此行
AppDelegate *appDelegate =
[[UIApplication sharedApplication] delegate];
// //create a frame for our signature capture based on whats remaining
imageFrame = CGRectMake(appDelegate.window.center.x,
appDelegate.window.center.y,
appDelegate.window.size.width,
appDelegate.window.bounds.size.width/1.5);