I have the following code:
- (id)initWithFrame:(CGRect)frame chapterNum:(int)newChapterNumber pageNum:(int)newPageNumber
{
NSLog (@"Frame:x:%f y:%f width:%f height:%f",frame.origin.x,
frame.origin.y,
开发者_运维知识库 frame.size.width,
frame.size.height);
self = [super initWithFrame:frame];
if (self) {
NSLog (@"View Frame:x:%f y:%f width:%f height:%f",self.frame.origin.x,
self.frame.origin.y,
self.frame.size.width,
self.frame.size.height);
......
}
Im running on the simulator (in landscape mode) when I look at the results of the console logs i see:
2011-06-17 09:17:16.428 MyApp[16454:207] Frame:x:0.000000 y:0.000000 width:128.000000 height:96.000000
2011-06-17 09:17:16.433 MyApp[16454:207] View Frame:x:-64.000000 y:-48.000000 width:128.000000 height:96.000000
Why is the origin of the View frame not the same as the frame im using , is it noteworthy that the value are exactly half of the size variables (plus a - sign). Any help is greatly appreciated !
First (and has nothing to do with the problem, just a style issue) use NSStringFromCGRect instead of printing it out yourself.
NSLog(@"frame = %@", NSStringFromCGRect(frame));
....
if(...) {
NSLog(@"self.frame = %@", NSStringFromCGRect(self.frame));
}
What view is your superclass? Is it a generic UIView or one of your making? Is there nothing in your initWithFrame:
method before the ....?
The significance of half your width and height becoming the new origin is that your view has had it's center
moved to 0,0. Not sure why it would be doing that, thus the question about your superclass.
For more info see the docs here and look at the docs for the center
property.
精彩评论