cgrect

Swift -Tabbar item frame is returning questionable value when converting frame to window

我的未来我决定 提交于 2021-01-29 17:22:48
问题 I have a tabBar with 5 items. To get the frame of the first tabBar item and set something based on that frame I use this which works perfectly: guard let firstTab = tabBarController?.tabBar.items?[0].value(forKey: "view") as? UIView else { return } guard let window = UIApplication.shared.windows.filter({$0.isKeyWindow}).first else { return } let windowRect = lastTab.convert(firstTab.frame, to: window) print(firstTab) // (2.0, 1.0, 79.00000000298023, 48.0) print(windowRect) // (4.0, 689.0, 79

Get CGRect of View

空扰寡人 提交于 2020-05-24 03:52:25
问题 I'm using a "RectGetter" to get the CGRect of a View . Like this: Text("Hello") .background(RectGetter(rect: self.$rect)) struct RectGetter: View { @Binding var rect: CGRect var body: some View { GeometryReader { proxy in self.createView(proxy: proxy) } } func createView(proxy: GeometryProxy) -> some View { DispatchQueue.main.async { self.rect = proxy.frame(in: .global) // crash here } return Rectangle().fill(Color.clear) } } But sometimes I get a crash when setting the rect. Thread 0 name:

iOS(CGGeometry)几何类方法总结

半城伤御伤魂 提交于 2020-03-01 02:44:58
iOS开发几何类方法总结 CGGeometry.h文件是用C语言实现的一个封装了许多常用几何方法的文件。 一、几个常用结构体 struct CGPoint { CGFloat x; CGFloat y; }; 定义一个点,设置x坐标和y坐标 struct CGSize { CGFloat width; CGFloat height; }; 定义一个尺寸,设置宽度和高度 struct CGVector { CGFloat dx; CGFloat dy; }; 定义一个二维矢量 struct CGRect { CGPoint origin; CGSize size; }; 定义一个矩形 二、几个系统定义的量 const CGPoint CGPointZero 零点,与 CGPointMake(0, 0) 等效 const CGSize CGSizeZero 零尺寸,与 CGSizeMake(0, 0) 等效 const CGRect CGRectZero 零矩形,与 CGRectMake(0, 0, 0, 0) 等效 const CGRect CGRectNull 空矩形,这个和零矩形并不相同,当我们返回两个不相交矩形的交集时,会返回空矩形。 const CGRect CGRectInfinite 无限的矩形 三、一些常用方法 CGPoint CGPointMake( CGFloat

Calculate Height Of NSAttributedString Containing HTML

限于喜欢 提交于 2020-02-05 05:31:04
问题 I am using NSAttributedString to display HTML text using the following code. do { let html = "<span style=\"font-family: Montserrat-ExtraLight; font-size: 14; line-height: 1.5;\">\(clinic.profile!)</span>" let clinicProfile = try NSAttributedString( data: (html.data(using: String.Encoding.unicode, allowLossyConversion: true)!), options: [ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType ], documentAttributes: nil ) contentView.attributedText = clinicProfile scrollView.addSubview

Change a UIView Frame

眉间皱痕 提交于 2020-01-21 20:10:33
问题 I have set a UIView in my storyboard and make it an outlet. @property (nonatomic, weak) IBOutlet UIView *testView; In the - (void)viewDidLoad method, I want to change its frame like this CGRect frame = self.testView.frame; frame.size.height = 2; self.testView.frame = frame; But it does not work. Anybody can tell me why? 回答1: You might enabled the autolayout in your project , if so the setFrame straightly won't work . Check here for more info Solution : Disable the autolayout, if you don't

Distance between two rectangles

北慕城南 提交于 2020-01-13 19:09:03
问题 How can I find the distance between two rectangles? Intersects should return 0 in distance. 回答1: Here's a quick function for calculating distance between two CGRects represented by a CGSize: CGSize CGSizeDistanceBetweenRects(CGRect rect1, CGRect rect2) { if (CGRectIntersectsRect(rect1, rect2)) { return CGSizeMake(0, 0); } CGRect mostLeft = rect1.origin.x < rect2.origin.x ? rect1 : rect2; CGRect mostRight = rect2.origin.x < rect1.origin.x ? rect1 : rect2; CGFloat xDifference = mostLeft.origin

Keep UIView inside Circle Objective-C

瘦欲@ 提交于 2020-01-13 17:23:23
问题 How can I have my Color Selector ( UIView ) to stay inside a color wheel that's 300px 300px? Im using the UIPanGestureRecognizer to drag the Color Selector around the color wheel UIImageView . The diameter of the color wheel is 300px. Here is the image of my UIViewController : The problem is that it can be dragged anywhere outside the wheel: So how can I keep my UIView that hovers over the color wheel say inside the circle? Your help is appreciated. 回答1: This really seems like more of a math

“Expression is not assignable” — Problem assigning float as sum of two other floats in Xcode?

我的未来我决定 提交于 2020-01-09 02:14:15
问题 In a piano app, I'm assigning the coordinates of the black keys. Here is the line of code causing the error. 'blackKey' and 'whiteKey' are both customViews blackKey.center.x = (whiteKey.frame.origin.x + whiteKey.frame.size.width); 回答1: The other answers don't exactly explain what's going on here, so this is the basic problem: When you write blackKey.center.x , the blackKey.center and center.x both look like struct member accesses, but they're actually completely different things. blackKey

“Expression is not assignable” — Problem assigning float as sum of two other floats in Xcode?

别说谁变了你拦得住时间么 提交于 2020-01-09 02:14:14
问题 In a piano app, I'm assigning the coordinates of the black keys. Here is the line of code causing the error. 'blackKey' and 'whiteKey' are both customViews blackKey.center.x = (whiteKey.frame.origin.x + whiteKey.frame.size.width); 回答1: The other answers don't exactly explain what's going on here, so this is the basic problem: When you write blackKey.center.x , the blackKey.center and center.x both look like struct member accesses, but they're actually completely different things. blackKey

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