开发者

copy uiimageview origin to CGPoint

I am new to iPhone/Objective-C programming. I have a UIImageView *myImage whose x,y,width,height are set using CGRect with values (20,20,100,100) or whatever;

Q1) When I do the following why can't i fetch the origin values into CGPoint.

CGPoint myPoint = myImage.frame.origin;

NSLog(@"X:%f Y:%f",mypoint.x, mypoint.y) /开发者_运维百科/ Prints X: 0.0 and Y: 0.0 instead of X:20.0 and Y: 20.o
NSLog(@"X:%f Y:%f",myImage.frame.origin.x, myImage.frame.origin.x) // Prints X: 20.0 and Y: 20.0  

The above NSLog statements do not print the expected values for myPoint but prints the right values for myImage.frame.origin. Why?

Q2) Also why can't I set @property to CGPoint ?


1) Have you tried :

CGPoint myPoint = CGPointMake(myImage.fram.origin.x, myImage.frame.origin.y);

2) After som testing I have found that you should be able to have your CGPoint as a property like this:

@interface MyClass : NSObject {

CGPoint myPoint;
...
}
@property (nonatomic) CGPoint myPoint;

...
@end

And then:

@implementation MyClass
@synthesize myPoint;

...

@end

that worked for me.

(I must admit I have not yet understood the (nonatomic) and if it is necessary but as long as it works...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜