cgrect

Crop image to a square according to the size of a UIView/CGRect

不打扰是莪最后的温柔 提交于 2019-12-05 18:18:08
问题 I have an implementation of AVCaptureSession and my goal is for the user to take a photo and only save the part of the image within the red square border, as shown below: AVCaptureSession's previewLayer (the camera) spans from (0,0) (top left) to the bottom of my camera controls bar (the bar just above the view that contains the shutter). My navigation bar and controls bar are semi-transparent, so the camera can show through. I'm using [captureSession setSessionPreset

Set background color for only part of UIView

情到浓时终转凉″ 提交于 2019-12-05 16:38:34
问题 I want the bottom (not quite half) of my UIView to be a different color than the top. I'm wondering if I should create a CGRect and then color that? Is this along the right track? - (void)drawRect:(CGRect)rect { CGRect aRect = CGRectMake(x, y, width, height); // Fill the rectangle with grey [[UIColor greyColor] setFill]; UIRectFill( rect ); } 回答1: Yes, as you are already overriding drawRect method, this will do. - (void)drawRect:(CGRect)rect { CGRect topRect = CGRectMake(0, 0, rect.size.width

How can I increase the size of a CGRect by a certain percent value?

ε祈祈猫儿з 提交于 2019-12-05 13:05:12
问题 How can I increase the size of a CGRect by a certain percent value? Should I use some form of CGRectInset to do it? Example: Assume I have a CGRect: {10, 10, 110, 110} I want to increase it's size (retaining the same center point) by 20% to: {0, 0, 120, 120} 回答1: You can use CGRectInset if you like: double pct = 0.2; CGRect newRect = CGRectInset(oldRect, -CGRectGetWidth(oldRect)*pct/2, -CGRectGetHeight(oldRect)*pct/2); To decrease the size, remove the - s. Side note : A CGRect that is 20%

MonoTouch convert color UIImage with alpha to grayscale and blur?

南笙酒味 提交于 2019-12-05 03:54:47
I am trying to find a recipe for producing a a blurred grayscale UIImage from a color PNG and alpha. There are recipes out there in ObjC but MonoTouch does not bind the CGRect functions so not sure how to do this. Any ideas? Here is one ObjC example of grayscale: (UIImage *)convertImageToGrayScale:(UIImage *)image { // Create image rectangle with current image width/height CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height); // Grayscale color space CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); // Create bitmap content with current image size and grayscale

Objective-C generating a random point which lies in given cgrect

…衆ロ難τιáo~ 提交于 2019-12-05 01:47:01
问题 my requirement is generating a random point in a given area, i.e i have an Cg Rectangle of some space and I need to generate a random point in this rectangle .. how can I proceed in this scenario? 回答1: - (CGPoint)randomPointInRect:(CGRect)r { CGPoint p = r.origin; p.x += arc4random_uniform((u_int32_t) CGRectGetWidth(r)); p.y += arc4random_uniform((u_int32_t) CGRectGetHeight(r)); return p; } 回答2: The original question asks specifically for Objective-C, but a Swift solution might help someone.

How to resize a modalViewController with UIModalPresentationPageSheet

℡╲_俬逩灬. 提交于 2019-12-04 21:35:05
I've a modal view controller that I show with UIModalPresentationPageSheet. The problem is that his default size is too large for my content: so I want to resize is frame to adjust in according with my content. Does anyone know a way/trick to do this ? Thanks You can't resize a UIModalPresentationPageSheet because its size is not modifable. Hrafn Actually you can resize the view controller that gets presented with UIModalPresentationPageSheet. To do it you need to create a custom view controller class and add the following to the class: <!--The header file--> @interface MyViewController:

Changing CGrect value to user coordinate system

风格不统一 提交于 2019-12-04 11:51:24
问题 I have a CGRect ; can I transfer its coordinates to be in the user coordinate system, i.e., bottom left corner to top instead of top left corner to bottom. Is there any predefined method for this or do I need to calculate it manually? Thanks in Advance. 回答1: To convert a rectangle from a coordinate system that has its origin at the bottom left (let's just call it traditional coordinate system to give it name) to a system where the origin is at the top left (iPhone coordinate system) you need

Child content view controller view has wrong bounds size from Storyboard?

て烟熏妆下的殇ゞ 提交于 2019-12-04 11:03:43
This document outline from my sample Storyboard shows what I'm working with. I have a custom container view controller and two content view controllers connected via embed segues. Here is the storyboard itself. ZetaViewController has to create some programmatic views (within ZetaView, of course). I noticed when I was centering these programmatically created views they seemed really off center. ZetViewController is centering things by examining self.view.bounds.size.height and self.view.bounds.size.width and doing some appropriate arithmetic. When I added debug logging to ZetaViewController, I

Subtract CGRect from CGRect — largest piece of one not containing the other

折月煮酒 提交于 2019-12-04 10:15:18
问题 How I can substract one CGRect from another? I want the result R1 - R2 to be the largest subrectangle of R1 that does not intersect R2. Example 1 : +----------------------------------+ | +--------+ | | | R2 | | | | | | | +--------+ R1 | | | | | | | +----------------------------------+ R3 = CGRectSubstract(R2,R1); +----------------------+ | | | | | | | R3 | | | | | | | +----------------------+ Example 2 : +-----------------------+----------+ | | | | | R2 | | | | | R1 +----------+ | | | | | | +

Swift SpriteKit edgeLoopFromRect Issue

痞子三分冷 提交于 2019-12-04 09:25:18
The following code recognizes the bottom and top edges of the scene and the ball bounces off as expected. However, the left and right edges of the scene are breached all the time. The ball goes off screen and then eventually returns back if enough force is applied. It is as if the edges of the scene are beyond the edges of the iphone simulator window. import SpriteKit class GameScene: SKScene { override func didMoveToView(view: SKView){ self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame) backgroundColor = UIColor.cyanColor() var ball = SKSpriteNode(imageNamed: "ball") ball.position