- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的应用有一个 UITableView,其中包含具有透明背景的可变高度单元格。针对 iOS 7 SDK 进行构建时,行删除动画存在问题:
请注意某些单元格的闪烁,例如第 15、17、21 和 23 行。在 iOS <= 6 上未观察到此行为。
如果我做了这些事情中的任何一个,问题就会消失(我还没有准备好做任何事情):
我尝试过的其他方法都没有帮助。在 iOS 7 上是否需要一些秘诀才能获得流畅的行删除动画?
这是我可以将问题提取到 [C#/Xamarin] 的最小测试用例:
public class MainViewController : UITableViewController {
public MainViewController() {
this.TableView.Source = new TableSource(this.TableView, 50);
}
public override void ViewDidAppear(bool animated) {
base.ViewDidAppear(animated);
NSTimer.CreateRepeatingScheduledTimer(0.5f, ((TableSource) this.TableView.Source).DeleteFirstRow);
}
}
public class TableSource : UITableViewSource {
private UITableView tableView;
private List<RowInfo> activeRows;
public TableSource(UITableView tableView, int numRows) {
this.tableView = tableView;
this.activeRows = new List<RowInfo>();
for (int i=1; i<=numRows; i++) {
this.activeRows.Add(new RowInfo(i));
}
}
public void DeleteFirstRow() {
if (this.activeRows.Count == 0) return;
this.activeRows.RemoveAt(0);
this.tableView.BeginUpdates();
this.tableView.DeleteRows(new NSIndexPath[] { NSIndexPath.FromRowSection(0, 0) }, UITableViewRowAnimation.Right);
this.tableView.EndUpdates();
}
public override int RowsInSection(UITableView tableview, int section) {
return this.activeRows.Count;
}
public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath) {
return this.activeRows[indexPath.Row].Height;
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) {
const string CellID = "Cell";
UITableViewCell cell = tableView.DequeueReusableCell(CellID);
if (cell == null) {
cell = new UITableViewCell(UITableViewCellStyle.Default, CellID);
}
cell.TextLabel.Text = this.activeRows[indexPath.Row].Text;
return cell;
}
public override void WillDisplay(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath) {
cell.BackgroundColor = UIColor.Clear;
}
private class RowInfo {
public RowInfo(int index) {
Random random = new Random(index);
this.Height = random.Next(20, 80);
this.Text = "Row " + index + " has height " + this.Height;
}
public float Height;
public string Text;
}
}
最佳答案
TLDR:cell.clipsToBounds = YES;
====
这是我发现的:
' | | | | <UITableViewCell: 0x79e81910; frame = (0 232; 320 32); text = 'row 27'; clipsToBounds = YES; autoresize = W; animations = { position=<CABasicAnimation: 0x79e8f020>; }; layer = <CALayer: 0x79e81aa0>>
| | | | | <UITableViewCellScrollView: 0x79e81ad0; frame = (0 0; 320 32); autoresize = W+H; gestureRecognizers = <NSArray: 0x79e81d60>; layer = <CALayer: 0x79e81ca0>; contentOffset: {0, 0}>
| | | | | | <UIView: 0x79e8b7d0; frame = (0 0; 320 51); clipsToBounds = YES; layer = <CALayer: 0x79e8b830>>
| | | | | | <UITableViewCellContentView: 0x79e81f50; frame = (0 0; 320 31.5); gestureRecognizers = <NSArray: 0x79e82160>; layer = <CALayer: 0x79e81fc0>>
| | | | | | | <UILabel: 0x79e821b0; frame = (15 0; 290 31.5); text = 'row 27'; userInteractionEnabled = NO; layer = <CALayer: 0x79e82260>>
| | | | | | <_UITableViewCellSeparatorView: 0x79e824d0; frame = (15 31.5; 305 0.5); layer = <CALayer: 0x79e82540>>
如果仔细查看第 27 行,您会注意到单元格的高度为 32 像素。单元格的 subview 是一个 ScrollView (我在某处读到它是您向左滑动以显示 iOS7 中的行操作的 ScrollView )。正如我们所见,contentView 的正确高度为 32px,但是,有趣的部分从这里开始:在 contentView 后面有一个 View ,其高度为 51px。我相信这是罪魁祸首。
不幸的是,我找不到那个 View (它不是 backgroundView,不是 selectedBackgroundView,等等,简而言之:它不是 UITableViewCell 类的公共(public)属性中的任何 View )。
另外,奇怪的是,该 View 的背景颜色是 clearColor。理论上它甚至不应该是可见的!我相信,我们在这里处理的是一些 CoreAnimation 优化,它不会渲染这个神秘 View 后面的区域。
因此,发生的情况是:1) 创建单元格 2) 调整单元格大小并准备好呈现 3) 单元格添加其神秘 View 并添加正确大小 4) 单元格被重新使用 5) 单元格调整为新大小动态高度 6) scrollView 和 contentView 也会调整大小,但神秘 View 不会(请注意它没有设置任何调整大小掩码)。
这解释了为什么您能够通过上述三种方法中的任何一种解决此问题。
解决方法是在创建时设置单元格的 cell.clipsToBounds = YES;
。我还建议不要设置 cell.backgroundColor。 IIRC,您应该为此使用 cell.backgroundView(将其设置为新创建的 View 并将其设置为 backgroundColor)。然而,单元格的默认 bacgroundColor 无论如何都是清晰的,因此在这种情况下这并不重要。
我很高兴听到有人告诉我这个私有(private) View 是干什么用的。
关于ios - UITableView 行删除动画在 iOS 7 上闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23129379/
我是 Jetpack Compose 的新手。我目前正在开发一个聊天应用程序。我要求用户从图库中选择图像或从相机中拍照。然后我将文件 Uri 保存到数据库中,然后收听所有消息的列表。更新此列表时,此图
强制性代码,但 jsFiddle 准确地演示了这个问题。我有一个在 3 秒内扩大和淡出的圆圈。声纳风格是我的意图。问题是动画完成后它会快速“闪烁”然后重新开始。 请在此处查看问题:http://jsf
您好,我有一个多种颜色的 Logo ,我想将其用于随机/不稳定的故意闪烁效果。我只能找到其他关于使用淡入/淡出功能进行闪烁技巧的文章。关于如何用 css3 和/或 jQuery 做这样的技巧有什么想法
我正在使用 Swing 创建组件并使用 GLCanvas (com.jogamp.opengl.awt.GLCanvas) 创建我的窗口。 接下来就是问题了 在初始状态下,一切正常,但是当我拖动窗口调
我将 PhoneGap 2.2.0 与 jQuery Mobile 1.2.0 结合用于我在 Android 平台(版本 2.3.3 及更高版本)上的应用程序。在我使用固定标题的页面上,根本没有转换。
在我们使用 JavaScript 向页面添加图像或文本后,我们的网页在 iPad 上闪烁。我们尝试了 -webkit-backface-visibility:hidden; 的各种组合; -webki
有人能告诉我为什么在这个使用 SwingWorker 的简单演示中,屏幕闪烁,好像按钮不断跳跃一样? (关于改进多线程部分的反馈也值得赞赏)。 import java.awt.EventQueue;
我正在运行时从 CSV 文件向字符串网格添加多行,但是 StringGrid 在更新时似乎会闪烁很多,我认为会有一个 beginupadate/Endupdate 命令来停止此操作。但是我找不到它。有
我的窗口中有一个文本元素,我希望它每隔几秒或几毫秒闪烁一次或出现并消失。 我的代码是: import QtQuick 2.6 import QtQuick.Window 2.2 Window {
我的窗口中有一个文本元素,我希望它每隔几秒或几毫秒闪烁一次或出现并消失。 我的代码是: import QtQuick 2.6 import QtQuick.Window 2.2 Window {
我在UIButtons中有3个UIView,它们具有相同的文本颜色和相同的背景颜色。轻按三个按钮即可触发相应的事件。但是只有其中之一会响应触摸而“闪烁”。其他两个会发生什么?它们有时(但很少)具有“闪
我在 iOS 8 下实现 UIRefreshControl 时遇到了一种闪烁。每次我第一次到达 tableView 的顶部时(即应用程序刚刚启动时),我都会看到下面的 gif 中显示的闪烁。这不会发生
我希望有人能帮助我。我遇到以下问题: http://jsfiddle.net/zhPAF/ 标记: About Us
当鼠标悬停在图像“A”上时,尝试让图像“B”覆盖在图像“A”上。理想情况下,我希望它淡入。 HTML: jQuery:
我有一个 TabControl,我可以在其中添加/删除多个 TabPage。 当我添加足够多的页面以至于必须显示导航按钮时,我遇到了闪烁问题。 当导航按钮(左右导航的 2 个箭头)未显示时,我根本没有
我尝试实现自定义双缓冲,但它会导致闪烁。 这是控件(继承自Control的自定义控件)构造函数中的代码: bufferContext = new BufferedGraphicsContext();
我有以下代码: var footer = $('.footer'), extra = 0; // footer.css({ opacity: '0', display: 'block' });
我遇到了与 JPanel 中闪烁相关的问题。不知道为什么, window 里的球时不时地闪烁。我尝试了几种方法,比如双缓冲、BufferStrategy、Canvas,但都不起作用。主要思想是使用线程
我试图在 OpenGL 中绘制一些文本,而程序绘制立方体或任何 Opengl native ,因此,当我尝试将文本放在屏幕上时,它闪烁得非常快,我不知道为什么,我试图改变 sleep 值什么都没有..
我已经使用 LibGDX UI Setup 启动了一个项目。 我在 implements ApplicationListener 中唯一拥有的是: public void create() {
我是一名优秀的程序员,十分优秀!