cgrect

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

送分小仙女□ 提交于 2019-11-30 18:20:39
问题 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. 回答1: 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 =

UIView height is not right on iPhone 5

*爱你&永不变心* 提交于 2019-11-30 12:07:55
问题 I am migrating my apps over and on one I use a UIPickerView . In the viewDidLoad method I create the picker and set it's y origin to be self.view.frame.size.height so that it is off screen. Then I just move it up when needed. On the iPhone 5 self.view.frame.size.height is still returning 480 yet the UIView fills the screen correctly. I've even tried using CGRectGetHeight(self.view.bounds) thinking that it may return something different...no dice. Any ideas as to why this maybe occurring. 回答1:

Can any one please explain what is use of CGRectZero

老子叫甜甜 提交于 2019-11-30 01:29:46
问题 I am new to iOS. Can any one please explain what the use is of CGRectZero and where it is used? 回答1: CGRectZero equals to CGRectMake(0,0,0,0). Usually it's used to fast-initialize CGRect object. For example: CGRect frame = CGRectZero; frame.size.width = someWidth; frame.size.height = someHeight; myView.frame = frame; From Apple's doc: /* The "zero" rectangle -- equivalent to CGRectMake(0, 0, 0, 0). */ CG_EXTERN const CGRect CGRectZero CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0); 回答2:

Get position of UIView in respect to its superview's superview

社会主义新天地 提交于 2019-11-29 19:04:36
I have a UIView, in which I have arranged UIButtons. I want to find the positions of those UIButtons. I am aware that buttons.frame will give me the positions, but it will give me positions only with respect to its immediate superview. Is there is any way we can find the positions of those buttons, withe respect to UIButtons superview's superview? For instance, suppose there is UIView named "firstView". Then, I have another UIView, "secondView". This "SecondView" is a subview of "firstView". Then I have UIButton as a subview on the "secondView". ->UIViewController.view --->FirstView A -------

Difference between frame.size.width and frame.width

浪子不回头ぞ 提交于 2019-11-29 09:31:53
I was writing a program in swift and just now I noticed that I can directly access a CGRect frame's width and height properties directly without using the CGSize width and height. That is I am now able to write a code like this. @IBOutlet var myView: UIView! override func viewDidLoad() { super.viewDidLoad() var height = myView.frame.height var height1 = myView.frame.size.height } In Objective C, when I tried to write the same code, the line height = view.frame.height is throwing an error. Can anyone please tell me the difference(if any) in these two lines of code. I just looked into the CGRect

How to get coordinates (CGRect) for the selected text in UIWebView?

爱⌒轻易说出口 提交于 2019-11-28 21:26:12
I have simple UIWebView with loaded html. I want to show the PopoverView pointed to the selected text. I can get the menuFrame of the UIMenuController and use its rect, but the result isn't as accurate at the corners of the screen as I need. I can calculate the screen size and get menuFrame rect and then I can suppose where the selection may be found, but I want exactly know where is the selected text. Is it generally possible? hwaxxer You can use the javascript function getBoundingClientRect() on the range object of the selected text. This is how I do it: function getRectForSelectedText() {

can a particular rect of UIview have different alpha..?

∥☆過路亽.° 提交于 2019-11-28 20:52:43
I wan't a imageview which is semi-transparent in other parts and completely transparent in the middle .. see this image.. i have managed to do it but it is not the best of ways.. can I only have a rect inside yellow lines transparent ...? EDIT : Is it possible to change the alpha of a certain rect of a view..? Gopal R Place a custom UIView over the view showing the image, size and position it to exactly overlap. In the custom view's drawRect method - (void)drawRect:(CGRect)rect { // Drawing code CGRect rBounds = self.bounds; CGContextRef context = UIGraphicsGetCurrentContext(); // Fill

iOS frame change one property (eg width)

人盡茶涼 提交于 2019-11-28 20:06:15
This question was originally asked for the objective-c programming language. At the time of writing, swift didn't even exist yet. Question Is it possible to change only one property of a CGRect ? For example: self.frame.size.width = 50; instead of self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 50); of course I understand that self.frame.size.width is read only so I'm wondering how to do this? CSS ANALOGY proceed at your own risk for those of you who are familiar with CSS , the idea is very similar to using: margin-left: 2px; instead of having to change

Cannot get current position of CALayer during animation

末鹿安然 提交于 2019-11-28 17:06:49
I am trying to achieve an animation that when you hold down a button it animates a block down, and when you release, it animates it back up to the original position, but I cannot obtain the current position of the animating block no matter what. Here is my code: -(IBAction)moveDown:(id)sender{ CGRect position = [[container.layer presentationLayer] frame]; [movePath moveToPoint:CGPointMake(container.frame.origin.x, position.y)]; [movePath addLineToPoint:CGPointMake(container.frame.origin.x, 310)]; CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; moveAnim

CGRectIntersectsRect Problem

时光总嘲笑我的痴心妄想 提交于 2019-11-28 11:49:46
问题 I am making a app with a maze, I put a ball inside the maze in the interface builder (I put an outlet for it) I have a touchesMoved: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint point; point = [touch locationInView:self.view]; ball.center = point; if (CGRectIntersectsRect(ball.frame, maze.frame)) { //my stuff } } I have two CGRectIntersectsRect if statements, I say, if the ball's frame touches the maze's frame, then