Tag: 石英

Contex绘图+分页

我正在尝试将scrollview内容scrollview到PDF上下文中,并且我正面临着pagination问题。 以下代码我已经使用: – (void)renderTheView:(UIView *)view inPDFContext:(CGContextRef)pdfContext { // Creating frame. CGFloat heightOfPdf = [[[self attributes] objectForKey:SRCPdfHeight] floatValue]; CGFloat widthOfPdf = [[[self attributes] objectForKey:SRCPdfWidth] floatValue]; CGRect pdfFrame = CGRectMake(0, 0, widthOfPdf, heightOfPdf); CGRect viewFrame = [view frame]; if ([view isKindOfClass:[UIScrollView class]]) { viewFrame.size.height = ((UIScrollView *)view).contentSize.height; [view setFrame:viewFrame]; } // Calculates number of pages. NSUInteger totalNumberOfPages […]

如何将atan2()映射到0-360度

atan2(y,x)在180°处有不连续点,在那里它顺时针转换到-180°.0°。 如何将数值范围映射到0°.360°? 这里是我的代码: CGSize deltaPoint = CGSizeMake(endPoint.x – startPoint.x, endPoint.y – startPoint.y); float swipeBearing = atan2f(deltaPoint.height, deltaPoint.width); 我正在计算给定startPoint和endPoint的滑动触摸事件的方向,都是XY点结构。 代码是为iPhone,但任何支持atan2f()的语言都可以。 感谢您的帮助,通用的解决scheme和代码。 更新 :我把erikkallen的答案变成了一个很好的长variables名,所以我从6个月后就可以理解它。 也许它会帮助其他iPhone noob。 float PointPairToBearingDegrees(CGPoint startingPoint, CGPoint endingPoint) { CGPoint originPoint = CGPointMake(endingPoint.x – startingPoint.x, endingPoint.y – startingPoint.y); // get origin point to origin by subtracting end from start float bearingRadians = atan2f(originPoint.y, originPoint.x); […]