cgfloat

Is there a constant for the maximum CGFloat value?

无人久伴 提交于 2019-12-20 10:16:08
问题 I need to create a CGSize to compute text height of an arbitrary text with arbitrary length. UIKit has this nice method -sizeWithFont:constrainedToSize: and my text is only constrained in width, but not in height. For this, I need to set the maximum possible CGFloat for the height. Is there a constant like "CGFloatMax"? 回答1: CGGeometry defines: #define CGFLOAT_MAX FLT_MAX 回答2: For those using Swift 2, you should use: CGFloat.max For those using Swift 3, you should use: CGFloat

heightForRowAtIndexPath crashing intermittently

落花浮王杯 提交于 2019-12-20 05:50:57
问题 I have an app with about 30 active users and 500+ registered users and this issue is only happening with one person who is on 9.2 using an iPhone 6. I can see from crash reports she's had over 60 crashes and she has said that the problem is OK sometimes and not others. I have the same test device here and no issue is happening. I can't get much out of the crash report details from fabric but the crash is happening at the following method and the app is crashing at the final else of this

Binary Operator + Cannot be Applied to Operands of Type CGfloat int

别等时光非礼了梦想. 提交于 2019-12-20 02:32:56
问题 I am having the same problem as earlier with a different line of code; but this time, I wasn't able to fix it with the same approach as last time: var Y : Int = 0 var X : Int = 0 @IBOutlet var ball : UIImageView! ball.center = CGPointMake(ball.center.x + X, ball.center.y + Y) This is the error I am getting: binary operator + cannot be applied to operands of type CGfloat int 回答1: Declare them, instead, as the following: let X : CGFloat = 0.0 let Y : CGFloat = 0.0 Replying to your comment: The

Convert Hex string to IEEE 754 float

二次信任 提交于 2019-12-16 18:03:44
问题 I am trying to convert a nsstring with hex values into a float value. NSString *hexString = @"3f9d70a4"; The float value should be = 1.230 . Some ways I have tried to solve this are: 1.NSScanner -(unsigned int)strfloatvalue:(NSString *)str { float outVal; NSString *newStr = [NSString stringWithFormat:@"0x%@",str]; NSScanner* scanner = [NSScanner scannerWithString:newStr]; NSLog(@"string %@",newStr); bool test = [scanner scanHexFloat:&outVal]; NSLog(@"scanner result %d = %a (or %f)",test

Cannot call value of non-function type 'CGFloat' with the alpha property

烂漫一生 提交于 2019-12-12 04:16:18
问题 I am debugging a dropdown menu I converted from Objective-C. In it, I have this function: func showMenu() { self.menu.hidden = false self.menu.translatesAutoresizingMaskIntoConstraints = true closedMenuShape.removeFromSuperlayer() if shouldDisplayDropShape { self.view.layer.addSublayer(openMenuShape) } // Set new origin of menu var menuFrame: CGRect = self.menu.frame menuFrame.origin.y = self.menubar.frame.size.height - self.offset() var containerAlpha: CGFloat = fadeAlpha if SYSTEM_VERSION

Changing an Int to a CGFloat in Swift to return heightForRowAtIndexPath tableview function

送分小仙女□ 提交于 2019-12-11 09:39:08
问题 I am sure that I am missing something really simple, but I just can't get it to work. I will try to explain better what I am doing to try to help others if they have this same issue. This was my function: func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return (count * 40 + 75) as CGFloat } The above function doesn't work. Thanks to the help I received, I found that this is the way to do it: func tableView(tableView: UITableView,

Use CGFloat instead of float? They don't do it

被刻印的时光 ゝ 提交于 2019-12-10 15:16:19
问题 [I might be misunderstanding this entire topic, as I've grown up with languages that allow the dev to almost entirely ignore processor architecture, like Java, except in some particular cases. Please correct me if I have some of the concepts wrong. ] Reading here it seems that the advice is to use CGFloat instead of, say, float, because it future-proofs my code for different processor architectures (64-bit handles float differently). Assuming that is right, then why does UISlider , for

Handling CGFloat with an NSScanner on arm64

孤者浪人 提交于 2019-12-10 14:55:50
问题 Apparently CGFloat is double on arm64: #if defined(__LP64__) && __LP64__ # define CGFLOAT_TYPE double # define CGFLOAT_IS_DOUBLE 1 # define CGFLOAT_MIN DBL_MIN # define CGFLOAT_MAX DBL_MAX #else # define CGFLOAT_TYPE float # define CGFLOAT_IS_DOUBLE 0 # define CGFLOAT_MIN FLT_MIN # define CGFLOAT_MAX FLT_MAX #endif So the code NSScanner *scanner = [NSScanner scannerWithString:string]; CGFloat c[components]; [scanner scanFloat:&c[i]] which was working fine for 32-bit apps, is broken for 64-bit

Conversion between CGFloat and NSNumber without unnecessary promotion to Double

吃可爱长大的小学妹 提交于 2019-12-10 13:54:29
问题 As we all know, CGFloat (which is ubiquitous in CoreGraphics, UIKit etc) can be a 32-bit or 64-bit floating point number, depending on the processor architecture. In C, CGFloat it is a typealias to float or double , in Swift is it defined as a struct CGFloat with a native property (which is Float or Double ). It has been observed repeatedly that a NSNumber can be created from and converted to Float and Double , but that there exist not similar conversions from and to CGFloat . The general

Replacement for `fabs`, `fmax`, etc. for use with CGFloat on 64-bit iOS devices

元气小坏坏 提交于 2019-12-09 14:55:06
问题 Question Consider layout code like this: CGFloat descriptionHeight = // height of a paragraph of text with zero or more words; CGFloat imageHeight = // height of an image; CGFloat yCoordinateOfSomeOtherView = fmax(descriptionHeight, imageHeight) + 5.0f; How should the third line be rewritten with support for 64-bit iOS devices? (The current code doesn't take into account whether yCoordinateOfSomeOtherView is a float or a double .) Options A few options (I'm not sure which is best): 1. Define