drawrect

How to open a new Intent inside OnTouch Event?

丶灬走出姿态 提交于 2019-12-01 01:49:00
I have a customized OnTouch Method where i check if the touch coordinates contains a rectangle.After checking the condition i want to start a new Activity.But unfortuanlely its not workin.Can someone help me out? public class custom extends SurfaceView implements SurfaceHolder.Callback{ public boolean onTouchEvent(MotionEvent event) { int touchX = (int) event.getX(); int touchY = (int) event.getY(); switch(event.getAction()){ case MotionEvent.ACTION_DOWN: System.out.println("Touching down!"); for(int i =0; i< rectangles.size();i++){ if(rectangles.get(i).contains(touchX,touchY)){ System.out

How many ways to calculate the FPS (Frames per second) of an iOS App programmatically?

大城市里の小女人 提交于 2019-11-30 21:42:39
Since we are talking about programmatically , Instruments are not under my consideration. Some reference listed in advance: Calculate fps (frames per second) for iphone app Display FPS on iOS onscreen (without Instruments) At what framerate does the iOS UI run animations at? 1. Using CADisplayLink According to the doc, The duration property provides the amount of time between frames. You can use this value in your application to calculate the frame rate of the display... So in my demo project, I add a displayLink to mainRunLoop for UITrackingRunLoopMode: self.displayLink = [CADisplayLink

what is the difference between UIImageView and drawInRect?

旧巷老猫 提交于 2019-11-30 10:26:51
问题 I want to display so many images in table cells. I knew two methods to show an image. One is creating an instance to UIImageView and show it CGRect rect=CGRectMake(x,y,width,height); UIImageView *image=[[UIImageView alloc]initWithFrame:rect]; [image setImage:[UIImage imageNamed:@"sample.jpg"]]; Another method is, CGRect rect=CGRectMake(x,y,width,height); [[UIImage imageNamed:@"sample.jpg"] drawInRect:rect]; Now, my question is, what is the difference between these two? Which one is efficient?

iOS UITableView with dynamic text and images rendered together (NSAttributedString + images)

半腔热情 提交于 2019-11-30 05:52:45
问题 My problem is this: I have dynamic content in an iOS app (such as twits - although this is not a twitter app) that include both text and images (mostly icons/emoticons and thumbnails). I want to render both text and images together in a table row. The main difficulty here is that each row will have a different size (making caching harder), and I need to calculate image size dynamically to fit text around on each image occurrence (I can have like 20 emoticons one next to another + text + more

How many ways to calculate the FPS (Frames per second) of an iOS App programmatically?

落爺英雄遲暮 提交于 2019-11-30 05:38:04
问题 Since we are talking about programmatically , Instruments are not under my consideration. Some reference listed in advance: Calculate fps (frames per second) for iphone app Display FPS on iOS onscreen (without Instruments) At what framerate does the iOS UI run animations at? 1. Using CADisplayLink According to the doc, The duration property provides the amount of time between frames. You can use this value in your application to calculate the frame rate of the display... So in my demo project

CGContextSaveGState vs UIGraphicsPushContext

隐身守侯 提交于 2019-11-29 16:51:03
问题 There are two drawRect methods: - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); // do drawing here CGContextRestoreGState(context); } And - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); UIGraphicsPushContext(context); // do drawing here UIGraphicsPopContext(); } UIGraphicsPushContext / UIGraphicsPopContext are from UIKit while CGContextSaveGState / CGContextRestoreGState are from

Getting a glyph boundingRect in draw#rect in UILabel. Fat bounty

怎甘沉沦 提交于 2019-11-29 14:21:55
Using Swift, I want to get the boundingRect of a glyph, in draw#rect in a UILabel, the UILabel already has a size (say 300x300 in the example) and qualities such as the text being centered. class RNDLabel: UILabel { override func draw(_ rect: CGRect) { let manager = NSLayoutManager() let store = NSTextStorage(attributedString: NSAttributedString( string: text!, attributes: [NSAttributedString.Key.font: font])) store.addLayoutManager(manager) let textContainer = NSTextContainer(size: rect.size) // note, intrinsicContentSize is identical there, no difference manager.addTextContainer

Color difference between drawRect and Interface Builder?

假如想象 提交于 2019-11-29 14:06:00
问题 Simply, I have 2 views in interface builder, one is set to the color 99,99,99 using the RGB sliders in interface builder. The other view is colored programmatically to achieve a certain shape. I fill it using: //Obviously, this is in drawRect. [[UIColor leadColor] set]; CGContextEOFillPath(myContext); //And this is a category on UIColor + (UIColor *)leadColor { return [UIColor colorWithWhite:99/255.0 alpha:1.0]; } The result: Why does this difference exist?? EDIT: (unecessary drawRect Code

iOS invert mask in drawRect

天涯浪子 提交于 2019-11-28 20:24:00
With the code below, I am successfully masking part of my drawing, but it's the inverse of what I want masked. This masks the inner portion of the drawing, where I would like to mask the outer portion. Is there a simple way to invert this mask? myPath below is a UIBezierPath . CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; CGMutablePathRef maskPath = CGPathCreateMutable(); CGPathAddPath(maskPath, nil, myPath.CGPath); [maskLayer setPath:maskPath]; CGPathRelease(maskPath); self.layer.mask = maskLayer; With even odd filling on the shape layer ( maskLayer.fillRule = kCAFillRuleEvenOdd; )

iOS draw filled Circles

核能气质少年 提交于 2019-11-28 16:41:48
Not a graphics programmer here, so I'm trying to stumble through this. I'm trying to draw 9 filled circles, each a different color, each with a white border. The UIView's frame is CGRectMake (0,0,60,60). See attached image. The problem is I'm getting "flat spots" on the borders on each side. Following is my code (from the UIView subclass): - (void)drawRect:(CGRect)rect { CGRect borderRect = CGRectMake(0.0, 0.0, 60.0, 60.0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0); CGContextSetRGBFillColor(context, colorRed, colorGreen,