UIImageview no se centrará en supervise

Tengo un UIImageView que agrego a una UIView para mejorar el área donde se reconocen los toques. Cuando trato de centrar el UIImageView en UIView (código a continuación), el centro se configura correctamente, pero cuando ejecuto el progtwig, la image se muestra muy lejos del marco de la UIView.

¿Algunas ideas?

// image size is 32x32 pixels but view will be created with 44x44 so touch recognition is better self = [super initWithFrame:CGRectMake(position.x, position.y, 44, 44)]; if (self) { switch (color) { case Blue: self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin_networking"]]; break; case Green: self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin_green"]]; default: break; } [self setCenter:position]; [self addSubview:self.imageView]; [self setExclusiveTouch:YES]; [self setBackgroundColor:[UIColor clearColor]]; [self.imageView setCenter:position]; NSLog(@"uiview center: %@", NSStringFromCGPoint(self.center)); NSLog(@"image center: %@", NSStringFromCGPoint(self.imageView.center)); 

¡Gracias!

The imageview setCenter es relativo a su padre. Tratar:

 [self.imageView setCenter:CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2)]; 
 UIImageView *imageforFace=[[UIImageView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2, 125,125)]; imageforFace.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin; [imageforFace setCenter:CGPointMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2)]; imageforFace.image=[UIImage imageNamed:@"face.png"]; [self.view addSubview:imageforFace]; 

Final, la salida es

introduzca la descripción de la imagen aquí

testing este código para dar UIImageView Frame Center de UIView

1) en el file .h

 UIImageView *imgCenter; 

2) en el file .m

 - (void)viewDidLoad { imgCenter=[[UIImageView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2, [UIScreen mainScreen].bounds.size.height / 2, 35, 35)]; [imgCenter setImage:[UIImage imageNamed:@"centerImage.png"]]; [self.view addSubview:imgCenter]; } 

O

 - (void)viewDidLoad { imgCenter=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 35, 35)]; imgCenter.center = self.view.center; [imgCenter setImage:[UIImage imageNamed:@"centerImage.png"]]; [self.view addSubview:imgCenter]; }