问题标签 [drawrect]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1524 浏览

uiview - UIView CGGradient 剪辑到绘制的“框架”

我正在尝试绘制更复杂的 UILabel(或 UIView,如果需要,将 UILabel 放在顶部)背景。因为我希望它在用户更改 iPhone 方向时自动调整大小,所以我试图在子类 drawRect 函数中实现它。如果可能的话,我希望能够在代码中调整这一切,省略对图案图像的需求。

我从有关该主题的一些以前的帖子中得到了一些提示:

iPhone 上的 UIView 和 UILabels 上的渐变,并使 UIView 的背景成为没有子类的渐变

不幸的是,他们都错过了目标,因为我想将渐变与自定义绘图结合起来。我希望 CGGradient 被我正在绘制的线框剪裁(在圆角处可见),但我无法做到这一点。

另一种方法是使用 CAGradientLayer,它似乎工作得很好,但这需要在旋转时对框架进行一些调整,并且无论我如何尝试,渐变层似乎都绘制在文本之上。

我的问题是双重的

  • 如何修改下面的代码以使渐变剪辑到绘制的“框架”
  • 如何让 CAGradientLayer 在 UILabel 的文本后面绘制(或者我是否必须在 UILabel 后面放置一个 UIView 并以 CAGradientLayer 作为背景)

这是我的drawrect函数:

0 投票
1 回答
581 浏览

iphone - UIView 子类创建自己的 UIButtons

我已经将 UIView 子类化了,所以我可以在其中画一些线。在这个 UIView 中有一大堆按钮,我决定将它们创建为在绘制线条后调用 drawRect 的方法。它可以工作,但有时只有部分按钮呈现。如果我删除按钮创建,而是在子类 UIViews 父级中添加 UIButton 它工作正常。

在 drawRect 方法中添加子视图之类的事情是一个很大的不,还是我不应该在 UIView 中一起做?

0 投票
1 回答
14745 浏览

iphone - Custom UITableViewCell and animation on setSelected:animated:

I have a UITableViewCell subclass that does its drawing in a drawRect: method. The whole rectangle is custom drawn, including the background. I was able to get very complex cells while keeping the scrolling very smooth.

My problem: I call [table deselectRowAtIndexPath:path animated:YES]; whenever the view appears, in order to comply with Apple's HIG. However, no animation occurs. It worked when I had a custom view (created with subviews) that was transparent (so Apple's background would appear below), of course. Now it doesn't.

My drawRect: is called once during the "animation time", about halfway through. I think this happens because it's animating the highlighted property of the cell from 1 to 0 and it snaps to 0 when it drops below 0.5.

How can I animate this transition? My guess would be to use the usual beginAnimations: etc. and animate a custom floating point field in my cell object from 1 to 0. Will this call drawRect: repeatedly to animate?

Update I managed to get this almost working. I've overridden setSelected:animated: like so:

This works perfectly if the table view is on-screen. But if I'm returning to the table view from navigation (back), instead of fading from selected to not selected, it fades from invisible to not selected. What can cause this?

0 投票
2 回答
1334 浏览

iphone - ViewController 中的“[self setNeedsDisplay:YES]”使应用程序崩溃

当我尝试在我的 ViewController 中运行 [self setNeedsDisplay:YES] 时,它会因发送到实例的无法识别的选择器而崩溃......我做错了什么吗?

我正在使用:

0 投票
2 回答
5178 浏览

iphone - 将轮廓阴影添加到与 iOS 3.0 兼容的 UIView

我有两个 UIViewControllers A 和 B,它们作为子视图添加到 AppDelegate 中,B 在 A 之上。

当点击 B 上的 UIButton 时,B 会向左滑动,代码如下:

在右边缘我想要一个 20px 的阴影,但我不能使用阴影属性,BView.view.layer.shadow....因为它只有 3.2/4.0+。而且动画的表现很糟糕,幻灯片非常滞后(没有阴影的流畅)。

我正在考虑使用自定义 UIView 并在 drawRect 中做一些魔术,但这是可能的还是我只能在视图的范围内绘制?

希望你们中的一些人和女孩可以帮助我。

干杯 objneodude

0 投票
2 回答
2020 浏览

iphone - 在没有drawRect的现有UIView上绘制线/点?

我创建了折线图。现在,当我点击屏幕时,我需要在此图表上显示点。最好的方法是什么?我需要drawRect再次调用方法,用标记点绘制整个图表吗?

我正在考虑图表上的透明层之类的东西UIView。我可以创建另一个透明UIView并将其放在图表的位置吗?

0 投票
1 回答
296 浏览

objective-c - 在 iPhone SDK 中刷新 UIView 需要帮助

我有一个简单的向下钻取导航应用程序。在详细视图中,我绘制了几个 20x20 大小的 UIImage,具体取决于导航项中选择的行。These images are drawn as subviews over the detail view when a row is selected.Now when I get to the "detail view" I have set up a couple of buttons, which when pressed, will rearrange the small images. 为此,我需要清除以前的图像并在视图的不同位置重新绘制它们。我有一个类似的方法: [MyView changeImagePositionwithPosnumber:"number selected by buttons"] 当按钮被按下时我不能通过这个方法,因为它会覆盖现有的图像。如何刷新视图以通过此方法?我需要为此实施绘制矩形吗?我不太了解drawrect,也不知道如何实现它。简而言之,当您离开详细视图时,无论导航控制器做什么,我都想做,所以我可以刷新我的视图并在其上绘制新图像。非常感谢您对此的任何帮助。我还是个新手。

0 投票
1 回答
2354 浏览

objective-c - 没有调用drawRect

我需要在一个矩形中绘制一个图像,因此我使用 drawRect 方法。我观察到它没有被调用。输出我只能看到空白屏幕。我正在使用 MAC OS,我需要在 Iphone OS 中测试应用程序3+。任何人都可以解决我的问题。这是我的代码:

我不知道我错在哪里:(

0 投票
2 回答
2001 浏览

iphone - 在 MKPolygonView 中绘制简单文本

您好,我尝试在 MKPolygonView 中绘制文本。我创建了 MKPolygonView 的子类并将其添加到我的 MKMapView。多边形正确显示,但我看不到文本。谁能帮我?

0 投票
2 回答
1059 浏览

iphone - 使用 drawRect: 和 setNeedsDisplay 方法的自定义单元格


在我的应用程序中有 3 个设置可以更改单元格的绘图。
默认情况下,我的表格视图的一个单元格显示对象的名称和成本...更改这 3 个设置,用户可以选择显示描述或成本链接。
我写了很多代码,现在,我的应用程序可以更改单元格的绘图而不退出它......
我的问题是绘图仅针对添加的新对象进行更改,但旧对象不会更改!
如何在不退出应用程序的情况下更改旧单元格的绘图?

这是我的单元格的代码(我正在使用 setNeedsDisplay 和 drawRect 方法):

非常感谢您的关注!
马修