将 uiimageview 原点复制到 CGPoint
我是 iPhone/Objective-C 编程新手。我有一个 UIImageView *myImage ,其 x,y,width,height 使用 CGRect 设置,值为 (20,20,100,100) 或其他;
Q1) 当我执行以下操作时,为什么我无法将原始值提取到 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
上面的 NSLog 语句不会打印 myPoint 的预期值,但会打印 myImage.frame.origin 的正确值。为什么?
Q2)为什么我不能将 @property 设置为 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)你尝试过吗:
2)经过一些测试,我发现你应该能够将 CGPoint 作为这样的属性:
然后:
这对我有用。
(我必须承认我还没有理解(非原子),如果有必要但只要它有效......)
1) Have you tried :
2) After som testing I have found that you should be able to have your CGPoint as a property like this:
And then:
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...)