uiview

UITapGestureRecognizer not working for specific [UIView] array

孤街浪徒 提交于 2020-01-05 04:24:10
问题 I have the following piece of code. It's a third party library for a menu (named CarbonKit). When I try to select a specific segment (tab) and add a gesture recognizer, it doesn't work. Any ideas what I'm doing wrong? To be clear, I placed a breakpoint in the handleTap, it it doesn't even enter the function. override func viewDidLoad() { super.viewDidLoad() self.view.userInteractionEnabled = true let tgr : UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector

Why moving UIView is not moving UIImageView on same view?

心已入冬 提交于 2020-01-05 03:33:45
问题 I have an ImageView on a UIView. I'm trying to move view keyboard size but all content move properly instead of UIImageView. -(void) keyboardWillShow:(NSNotification *) notification { NSDictionary* keyboardInfo = [notification userInfo]; // Work out where the keyboard will be NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; // Work out animation duration NSTimeInterval animationDuration

Why does UIView not stay on centre while it rotates?

ぃ、小莉子 提交于 2020-01-05 03:33:15
问题 I am trying to calibrate a UIView to stay on centre as it rotates. This follows up a problem identified by the best answers to my previous question. I have since devised code based on one answer proposing to use viewWillAppear or viewDidLayoutSubviews instead of viewDidLoad . As I am new to Swift I had to revisit the Swift tutorial Implement a Custom Control which describes how to make a subClass of UIView. My code can draw a circle using any one of three functions: viewWillAppear ,

How do you balance Auto Layout with creating frames?

橙三吉。 提交于 2020-01-05 02:55:32
问题 When I'm creating a frame in iOS with CGRectMake() , be it setting the frame property or using initWithFrame: , it asks for the x, y, width and height. I supply these. But with Auto Layout, I'm next going to say something like: "position its x in the very middle" and "set the width to half the screen", right after I set those with CGRectMake() likely differently. What do I set them as in CGRectMake() ? 0? An arbitrary value? Something close to what I want? 回答1: When using auto-layout, you

Any example iPhone code for an Analog Clock?

五迷三道 提交于 2020-01-05 02:50:09
问题 Interested in creating by own analog clock application - anyone know of some example project/code that implements an analogue clock? (i.e. not a digital clock). Ideally with a custom background, and custom hour/minute hands as images? I note that the following link exists, however was hoping for something just a little more specific to matching what I'm doing (background image, images for the hour/minute hands): Example Code 回答1: Create a background image, and images for each of the hands

Custom UITabBarController Problems with View Controllers and Views

不羁的心 提交于 2020-01-05 02:32:27
问题 I'm writing a custom UITabBarController so I can fully control appearance of the tab bar. I've got it all working so I have an array of view controllers that it handles. The controller has a main view which fills the screen, and inside it it has a UIView at the bottom for the tab bar. That tab bar view has a button for each view controller. When buttons are pressed I add the view controller's view to the main view, and set it's frame so that it doesn't cover the tab bar view: controller.view

UIGraphicsGetCurrentContext didn't appear inside UIView

若如初见. 提交于 2020-01-04 13:47:54
问题 I have to draw a shape and detect if user touches are inside the shape or not, so I defined a custom class inherit from UIView as follow : class ShapeView: UIView { override init(frame: CGRect) { super.init(frame: frame) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func draw(_ rect: CGRect) { drawShape() } func drawShape() { guard let ctx = UIGraphicsGetCurrentContext() else { return } let zero = CGPoint(x: frame.midX, y: frame

UIGraphicsGetCurrentContext didn't appear inside UIView

三世轮回 提交于 2020-01-04 13:47:16
问题 I have to draw a shape and detect if user touches are inside the shape or not, so I defined a custom class inherit from UIView as follow : class ShapeView: UIView { override init(frame: CGRect) { super.init(frame: frame) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func draw(_ rect: CGRect) { drawShape() } func drawShape() { guard let ctx = UIGraphicsGetCurrentContext() else { return } let zero = CGPoint(x: frame.midX, y: frame

UIView drawRect vs initWithFrame

六眼飞鱼酱① 提交于 2020-01-04 09:17:08
问题 I have a UIView which has several buttons added to it as subviews. Currently I have the buttons in drawRect:, which I have heard is a bad idea because drawRect can be called several times. I tried to move these UIButtons to initWithFrame, but they just don't get drawn. How should I fix this? I am not using interface builder, so there are no NIB files present. The initWithFrame is called. I checked by adding an NSLog(...), and my NSMutableArrays are being properly initialized. My initWitFrame:

How to get rid of thin border in a UIView rounded with layer.cornerRadius in iOS 7.1.1?

心不动则不痛 提交于 2020-01-04 07:26:30
问题 I have a customized UIView that rounds its corners by using layer.cornerRadius like this: - (void)layoutSubviews { [super layoutSubviews]; self.layer.cornerRadius = self.frame.size.width / 2.0; self.layer.borderColor = [UIColor whiteColor].CGColor; self.layer.borderWidth = 2.0; self.layer.masksToBounds = YES; self.backgroundColor = [UIColor redColor]; } How can I get rid of the very thin outer red circle? 回答1: Well, a more efficient way to do what you need would be to copy paste this function