cgpoint

finding location of specific characters in UILabel on iPhone

孤人 提交于 2019-11-28 11:34:25
I have a UILabel with some text, say "Hello World abcdefg" The label can have multiple lines, different font sizes etc. Question : How do I find the coordinates of all letters "d" in this UILabel. Logical first step is find the position of those characters in the string (UILabel.text), but then how do I translate that into coordinates when it's actually drawn on screen The idea is to find those coordinates and draw something custom on top of that character (basically to cover it with a custom image) The basic tools for measuring text on iPhone are in UIStringDrawing.h but none of them do what

Rotating a CGPoint around another CGPoint

倾然丶 夕夏残阳落幕 提交于 2019-11-28 08:13:24
问题 Okay so I want to rotate CGPoint(A) 50 degrees around CGPoint(B) is there a good way to do that? CGPoint(A) = CGPoint(x: 50, y: 100) CGPoint(B) = CGPoint(x: 50, y: 0) Here's what I want to do: 回答1: This is really a maths question. In Swift, you want something like: func rotatePoint(target: CGPoint, aroundOrigin origin: CGPoint, byDegrees: CGFloat) -> CGPoint { let dx = target.x - origin.x let dy = target.y - origin.y let radius = sqrt(dx * dx + dy * dy) let azimuth = atan2(dy, dx) // in

applyImpulse towards CGPoint SpriteKit

守給你的承諾、 提交于 2019-11-28 06:40:59
问题 I'm kind of a newb in SpriteKit, game dev, as a matter of fact I'm just learning. So I got to a point where I what to move a bunch of nodes towards a users tap location. So far I fought that I might calculate a virtual right triangle and get sin and cos of angles based on the sides. Unfortunately that left me with a very strong impulse that doesn't really consider the user tap location. Any ideas? Thanks in advance. 回答1: Look up the shooting projectiles section in the tutorial by Ray

Objective-c: How to rotate CGRect

拜拜、爱过 提交于 2019-11-28 04:01:51
问题 I've tried to rotate my rectangle, but it does not work properly. Here is part of my code, I found it in another post: #define DEGREES_TO_RADIANS(x) (M_PI * x / 180.0) -(void)drawRect:(NSRect)rect { CGContextRef cRef = [[NSGraphicsContext currentContext] graphicsPort]; // points[] - this is a CGPoints array, length_one is a double value CGRect rect_one = CGRectMake(points[0].x, points[0].y, (CGFloat)length_one, 40); // I've print out the origin of old one and new one NSLog(@"old rect -- %f,

Getting Pixel Color from an Image using CGPoint in Swift 3

拈花ヽ惹草 提交于 2019-11-28 01:47:01
问题 I am try this PixelExtractor class in Swift 3, get a error; Cannot invoke initializer for type 'UnsafePointer' with an argument list of type '(UnsafeMutableRawPointer?)' class PixelExtractor: NSObject { let image: CGImage let context: CGContextRef? var width: Int { get { return CGImageGetWidth(image) } } var height: Int { get { return CGImageGetHeight(image) } } init(img: CGImage) { image = img context = PixelExtractor.createBitmapContext(img) } class func createBitmapContext(img: CGImage) ->

How to convert CGPoint in NSValue in swift?

霸气de小男生 提交于 2019-11-27 19:22:58
问题 As my question title says how can I convert CGPoint into NSValues so I can store then Into array In swift . In objective-C we can do it like this: // CGPoint converted to NSValue CGPoint point = CGPointMake(9, 9); NSValue *pointObj = [NSValue valueWithCGPoint:point]; But can anybody tell me that how can I do this in swift? Thanks In Advance. 回答1: Try something like that: let point = CGPointMake(9, 9) var pointObj = NSValue(CGPoint: point) 回答2: Exactly as you'd imagine: let point = CGPoint(x:

How to test if a point is in a view

陌路散爱 提交于 2019-11-27 13:37:39
问题 I have a UIImageView and I have a CGPoint on the screen. I want to be able to test that point to see if it is in the UIImageView . What would be the best way to do this? 回答1: CGPoint is no good with a reference point. If your point is in window's coordinates then you can get it using CGPoint locationInView = [imageView convertPoint:point fromView:imageView.window]; if ( CGRectContainsPoint(imageView.bounds, locationInView) ) { // Point lies inside the bounds. } You may also call pointInside

How to get a CGPoint from a tapped location?

坚强是说给别人听的谎言 提交于 2019-11-27 07:26:39
I'm working on a graphing calculator app for the iPad, and I wanted to add a feature where a user can tap an area in the graph view to make a text box pop up displaying the coordinate of the point they touched. How can I get a CGPoint from this? Paras Joshi you have two way ... 1. -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:touch.view]; } here,you can get location with point from current view... 2. UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]

Accessing the current position of UIView during animation

纵然是瞬间 提交于 2019-11-27 02:10:32
问题 I am trying to find the current position of an iPhone ImageView that is animating across the screen. I create and animate the imageView like so -(IBAction)button:(UIButton *)sender{ UIImageView *myImageView =[[UIImageView alloc] initWithImage: [UIImage imageNamed:@"ball.png"]]; myImageView.frame = CGRectMake(0, self.view.frame.size.height/2, 40, 40); [self.view addSubview:myImageView]; [myArray addObject:myImageView]; [UIView animateWithDuration:.5 delay:0 options: