cgrect

IOS: verify if a point is inside a rect

我是研究僧i 提交于 2019-12-03 01:25:15
问题 Is there a way to verify if a CGPoint is inside a specific CGRect . An example would be: I'm dragging a UIImageView and I want to verify if its central point CGPoint is inside another UIImageView 回答1: Swift 4 let view = ... let point = ... view.bounds.contains(point) Objective-C Use CGRectContainsPoint(): bool CGRectContainsPoint(CGRect rect, CGPoint point); Parameters rect The rectangle to examine. point The point to examine. Return Value true if the rectangle is not null or empty and the

How to resize UITextView while typing inside it?

こ雲淡風輕ζ 提交于 2019-12-02 23:17:59
I'm creating a comment section much like the one Facebook uses for it's messaging section in it's iOS app. I want the UITextView to resize the height so the text I'm typing fits inside it rather than you having to scroll to see the text that overflows. Any ideas how I might go about doing this? I've looked into maybe using a CGRect that is assigned to the size and height of the text view which then matches the content size: CGRect textFrame = textView.frame; textFrame.size.height = textView.contentSize.height; textView.frame = textFrame; I assume I need some sort of function that detects when

Turn two CGPoints into a CGRect

假装没事ソ 提交于 2019-12-02 22:21:31
How can I, given two different CGPoints , turn them into an CGRect ? Example: CGPoint p1 = CGPointMake(0,10); CGPoint p2 = CGPointMake(10,0); How can I turn this into a CGRect ? This will take two arbitrary points and give you the CGRect that has them as opposite corners. CGRect r = CGRectMake(MIN(p1.x, p2.x), MIN(p1.y, p2.y), fabs(p1.x - p2.x), fabs(p1.y - p2.y)); The smaller x value paired with the smaller y value will always be the origin of the rect (first two arguments). The absolute value of the difference between x values will be the width, and between y values the height. colinta A

extension function screenshot not capturing the same area in iphone and ipad

牧云@^-^@ 提交于 2019-12-02 17:59:53
问题 I am using a extension function to take a screenshot of a uiview. The problem is that the results look very different. I want the photo to look the same regardless of weather its a ipad or iphone. I am manually entering the constraints so I expect the images to be the same. I want to using the function to go to the orgin or center of the viewcontroller and be 200 height and 200 width. So the image should be the same regardless of the device because it starts in the center and is the same size

IOS: verify if a point is inside a rect

为君一笑 提交于 2019-12-02 14:46:12
Is there a way to verify if a CGPoint is inside a specific CGRect . An example would be: I'm dragging a UIImageView and I want to verify if its central point CGPoint is inside another UIImageView Ole Begemann Swift 4 let view = ... let point = ... view.bounds.contains(point) Objective-C Use CGRectContainsPoint() : bool CGRectContainsPoint(CGRect rect, CGPoint point); Parameters rect The rectangle to examine. point The point to examine. Return Value true if the rectangle is not null or empty and the point is located within the rectangle; otherwise, false. A point is considered inside the

Error while using property 'CGRectGetWidth', it says it was replaced with 'CGRect.width'

最后都变了- 提交于 2019-12-02 10:10:50
问题 When I'm using this code, I get an error: let d = translation.x / CGRectGetWidth(pan.view!.bounds) * 0.5 'CGRectGetWidth' has been replaced by property 'CGRect.width' How can I fix this? 回答1: You should get the width directly from the bounds property. let d = translation.x / pan.view!.bounds.width * 0.5 回答2: CGRectGetWidth has been removed in swift 3 and now you can get width directly let d = translation.x / (pan.view!.bounds.width) * 0.5 hope its works.. 来源: https://stackoverflow.com

Error while using property 'CGRectGetWidth', it says it was replaced with 'CGRect.width'

一世执手 提交于 2019-12-02 03:30:33
When I'm using this code, I get an error: let d = translation.x / CGRectGetWidth(pan.view!.bounds) * 0.5 'CGRectGetWidth' has been replaced by property 'CGRect.width' How can I fix this? You should get the width directly from the bounds property. let d = translation.x / pan.view!.bounds.width * 0.5 CGRectGetWidth has been removed in swift 3 and now you can get width directly let d = translation.x / (pan.view!.bounds.width) * 0.5 hope its works.. 来源: https://stackoverflow.com/questions/48786472/error-while-using-property-cgrectgetwidth-it-says-it-was-replaced-with-cgrec

Convert CGPoint from CGRect to other CGRect

≯℡__Kan透↙ 提交于 2019-12-01 19:29:07
I have placed one label on view and view's frame is CGRectMake(0,0,270,203) . Now I have to take screen shot of view with CGRectMake(0,0,800,600) . So I have to convert label from old rect to new rect . here is code which I used to take screen shot: CGRect rect = [view bounds]; UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); [view.layer renderInContext:context]; UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); Here is the code which I used to convert point: CGRect f = [view

Make view cover full screen using CGRectMake

人走茶凉 提交于 2019-12-01 18:52:48
I'm creating a view (using card.io), and I want the view to cover the full screen. Its only covering about 2/3rds of the screen atm. Heres the code: CardIOView *cardIOView = [[CardIOView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)]; Here is an example Dave from card.io here. When you create a CardIOView , its frame will take on whatever size you set. However, the camera view within the (transparent) CardIOView will have the standard iOS camera form factor of 4:3. So if the CardIOView is 320 points wide, then its camera view will be ~426 points

How to make the frame of a button custom shape in Swift 2

倾然丶 夕夏残阳落幕 提交于 2019-11-30 23:53:47
I want the button to be reactive to tap only in the custom polygonal shape that I create and not in the CGRect frame. button.frame only supports CGRect. Here is an example of a button that only responds to touches within a certain area. class MyButton: UIButton { var path: UIBezierPath! override func awakeFromNib() { backgroundColor = UIColor.greenColor() addTarget(self, action: #selector(touchDown), forControlEvents: .TouchDown) } override func drawRect(rect: CGRect) { path = UIBezierPath() path.moveToPoint(CGPointMake(150, 10)) path.addLineToPoint(CGPointMake(200, 10)) path.addLineToPoint