在绘制之前不要清除上下文(Don't clear the context before drawing)
我试图找到一种方法在视图上绘制线条而不重绘所有上下文。
这是我的绘图方法:
-(void)drawInContext:(CGContextRef)context { for (int i = 0; i < self.drawings.count; ++i) { Drawing* drawing = [self.drawings objectAtIndex:i]; CGContextSetStrokeColorWithColor(context, drawing.colorTrait.CGColor); CGContextSetLineWidth(context, 1.0); CGContextMoveToPoint(context, [[drawing.points objectAtIndex:0] CGPointValue].x * self.zoomScale, [[drawing.points objectAtIndex:] CGPointValue].y * self.zoomScale); for (int i = 1; i < drawing.points.count; i++) { CGContextAddLineToPoint(context, [[drawing.points objectAtIndex:i] CGPointValue].x * self.zoomScale, [[drawing.points objectAtIndex:i] CGPointValue].y * self.zoomScale); } CGContextStrokePath(context); } } -(void)drawRect:(CGRect)rect { if (isRedrawing) { [self drawInContext:UIGraphicsGetCurrentContext()]; isRedrawing = NO; } [[UIColor redColor] set]; [currentPath stroke]; }
但是当我在触摸方法中调用setNeedsDisplay时,视图完全被清除。 有没有办法让我的方法有效?
I'm trying to find a way to draw lines on a view without redrawing all the context.
Here is my drawing methods :
-(void)drawInContext:(CGContextRef)context { for (int i = 0; i < self.drawings.count; ++i) { Drawing* drawing = [self.drawings objectAtIndex:i]; CGContextSetStrokeColorWithColor(context, drawing.colorTrait.CGColor); CGContextSetLineWidth(context, 1.0); CGContextMoveToPoint(context, [[drawing.points objectAtIndex:0] CGPointValue].x * self.zoomScale, [[drawing.points objectAtIndex:] CGPointValue].y * self.zoomScale); for (int i = 1; i < drawing.points.count; i++) { CGContextAddLineToPoint(context, [[drawing.points objectAtIndex:i] CGPointValue].x * self.zoomScale, [[drawing.points objectAtIndex:i] CGPointValue].y * self.zoomScale); } CGContextStrokePath(context); } } -(void)drawRect:(CGRect)rect { if (isRedrawing) { [self drawInContext:UIGraphicsGetCurrentContext()]; isRedrawing = NO; } [[UIColor redColor] set]; [currentPath stroke]; }
But when I call setNeedsDisplay in my touches methods, the view is entirely cleared. Is there a way to make my method work ?
原文:https://stackoverflow.com/questions/13828633
更新时间:2023-09-14 21:09
最满意答案
那是因为当您单击hideButton时,您已将图像的可见性设置为不可见。 您需要再次显示图像。
在第一个按钮的onClick侦听器中,添加以下行:
image.setVisibility(View.VISIBLE);
That's because you've set the image's visibility to invisible when you click the hideButton. You need to make the image visible again.
In your first button's onClick listener, add the following line:
image.setVisibility(View.VISIBLE);
相关问答
更多-
你可以使用mButton.setVisibility(View.GONE)来隐藏按钮。 您还可以使用mButton.isShown()来检查按钮在布尔变量中的可见性状态。 编辑: 例如 在AppWidgetProvider onReceive()中, remoteViews = new RemoteViews( context.getPackageName(), R.layout.yourwidgetlayout ); remoteViews.setViewVisibility(vie ...
-
您必须以编程方式执行此操作添加: ActionBar中动作/菜单项的动态控制 ,删除: 如何隐藏操作栏中的菜单项? ,你可以使用一个标志,然后调用invalidateOptionsMenu()来更新你在菜单项上所做的更改,我现在没有一个例子,但我认为通过这个解释你应该实现你想要做的。 另一种方法是在方法onCreateOptionsMenu添加MenuItem(或者直接通过UI XML),然后在方法onPrepareOptionsMenu隐藏编辑按钮并使用之前提到的方法用setVisible()方法更新显示 ...
-
如果要实现浮动按钮,更好的方法是使用现有库: 在build.gradle依赖项上添加以下行: compile 'com.getbase:floatingactionbutton:1.3.0' 并将您的布局更改为:使用ImageButton,然后使用android:background来设置图像 Use ImageButton, then use android:background to set the image
android中的图像按钮样式(Image button style in android)[2022-07-13]
把这个标签放在ImageButton android:background="@null" 这将做到这一点。 Put this tag in your ImageButton android:background="@null" This will do it.在Android中按下按钮时,逐渐显示或隐藏布局(Gradually show or hide a layout on swiping on a button in Android)[2022-11-06]
private float x1,x2; static final int DISTANCE = 100; 和setOnTouchListener on按钮。 然后重写onTouchEvent: @Override public boolean onTouchEvent(MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_DOWN: x1 = event.getX(); ...隐藏和显示图像的按钮在Android中无法正常工作(hide and show button for an image is not working randomely in android)[2023-09-07]
那是因为当您单击hideButton时,您已将图像的可见性设置为不可见。 您需要再次显示图像。 在第一个按钮的onClick侦听器中,添加以下行: image.setVisibility(View.VISIBLE); That's because you've set the image's visibility to invisible when you click the hideButton. You need to make the image visible again. In your fir ...你已经使用了给你OnTouchListener 。 使用它们! 只要您按下按钮,无需再次检查按钮MotionEvent在那里。 使用密码输入密码字段: inputType = TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD inputType = TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD 当按下按钮时MotionEvent.ACTION_UP所以你可以看到文字。 当MotionE ...在Style.xml ,您需要使用AppCompat主题 - ( 推荐 ) 以上主题是Material Light主题。 否则,您可以离开AppCompat (但我建议不要这样,因为AppCompat用于较低Android版本的 ...相关文章
更多- Don’t work. Be hated. Love someone.
- Map、List集合类的清空使用clear还是重新new呢
- Tomcat6 不修改server.xml和conf/context.xml配置数据源的问题.
- 转载收藏之用 - 微信公众平台开发教程(七):解决用户上下文(Session)问题
- Senparc.Weixin.MP SDK 微信公众平台开发教程(七):解决用户上下文(Session)问题
- Senparc.Weixin.MP SDK 微信公众平台开发教程(七):解决用户上下文(Session)问题
- JOGL绘制图形
- solr dataimport 数据导入源码分析(五)
- 用C#捕捉键盘和鼠标
- 关于如何参与到开源项目中《How To Succeed In Open Source ( In Ways You Haven't Considered Yet )》
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)