在我们的应用程序中,我们在CAEAGLLayer上面有UIScrollView.UIScrollView包含一些UIViews(红色矩形).在CAEAGLLayer中,我们绘制白色矩形.白色矩形的中心与红色矩形的中心相同.当UIScrollView滚动时,我们更新CAEAGLLayer中白色矩形的位置并渲染它们.
我们得到了预期的结果:白色矩形的中心总是与红色矩形的中心相同.
但是我们无法将CAEAGLLayer的更新与UIScrollView中的视图移动同步.我们有一些错误 - 红色矩形落后于白色矩形.
粗略地说,我们真的想让CAEAGLLayer与UIScollView一起延迟.
我们准备了示例代码.在设备上运行并滚动,您将看到白色矩形(由OpenGL绘制)比红色矩形(常规UIViews)移动得更快.在scrollViewDidScroll:委托调用中正在更新OpenGL.
https://www.dropbox.com/s/kzybsyu10825ikw/ios-opengl-scrollview-test.zip
它在iOS模拟器中的行为相同,只需看一下视频:http://www.youtube.com/watch?v = 1T9hsAVrEXw
红色= UIKit,白色= OpenGL
代码是:
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
// reuses red squares that are gone outside thw bounds
[overlayView updateVisibleRect:CGRectMake(...)];
// draws white squares using OpenGL under the red squares
[openGlView updateVisibleRect:CGRectMake(...)];
}
Run Code Online (Sandbox Code Playgroud)
在简化的样本中可以很容易地证明同样的问题.工作的xcodeproj可以在以下位置找到:
https://www.dropbox.com/s/vznzccibhlf8bon/simple_sample.zip
示例项目基本上在OpenGL中绘制和动画一组WHITE方块,并为RED组的UIViews做同样的操作.红色和白色方块之间很容易看到滞后.
我的代码有一个非常奇怪的错误.事实上,根本没有错误,只是调试器以"程序接收信号:"EXC_BAD_ACCESS""消息开始.谁能帮我?我完全糊涂了......谢谢.
-(NSString *)fullNameForPhone:(NSString *)ph withAlternativeText:(NSString *)text
{
ABAddressBookRef addressBookRef = ABAddressBookCreate();
NSLog(@"create addressBookRef");
NSString *stringToReturn = text;
CFArrayRef allPeopleRef = ABAddressBookCopyArrayOfAllPeople(addressBookRef);
NSLog(@"create allPeopleRef");
CFIndex nPeople = ABAddressBookGetPersonCount(addressBookRef);
int i = 0;
BOOL nameFound = NO;
while ((i < nPeople) && (!nameFound))
{
ABRecordRef recordRef = CFArrayGetValueAtIndex(allPeopleRef, i);
NSLog(@" create recordRef");
CFStringRef allRecordPhonesRef = ABRecordCopyValue(recordRef, kABPersonPhoneProperty);
NSLog(@" create allRecordPhonesRef");
CFIndex nPhones = ABMultiValueGetCount(allRecordPhonesRef);
int currentPhone = 0;
for (currentPhone = 0; currentPhone < nPhones; currentPhone++)
{
CFStringRef currentPhoneNumberRef = ABMultiValueCopyValueAtIndex(allRecordPhonesRef, currentPhone); …Run Code Online (Sandbox Code Playgroud)