में केंद्रित नहीं होगा मेरे पास UIImageView है जो मैं उस क्षेत्र को बढ़ाने के लिए UIView में जोड़ता हूं जहां स्पर्श पहचाने जाते हैं। जब मैं UIView (नीचे कोड) में UIImageView को केन्द्रित करने का प्रयास करता हूं तो केंद्र ठीक से सेट होता है लेकिन जब मैं प्रोग्राम चलाता हूं तो छवि UIView के फ्रेम के बाहर दिखाई देती है।UIImageview पर्यवेक्षण
कोई विचार?
// 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_red"]];
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));
धन्यवाद!
त्वरित जवाब के लिए धन्यवाद है, लेकिन अगर मैं कोशिश [self.imageView setCenter: self.center] नतीजा वही है :-( – illogic
जो मैं सुझाव दे रहा था वह नहीं था। आपको एक बिंदु प्राप्त करने की आवश्यकता है जो माता-पिता के सापेक्ष है। self.center इसे अपने माता-पिता के सापेक्ष वापस कर देगा, और – tillerstarr
पर काम नहीं करना चाहिए, लेकिन स्वयं पर्यवेक्षक है और इसलिए यह इस मामले में अभिभावक है। या मैं गलत हूँ? – illogic