Objective:TogetaUIView,whichisasmallmagnifyingglass,tobeplacedabovethenavigationcon
Objective: To get a UIView, which is a small magnifying glass, to be placed above the navigation controller. It's exactly like the loupe in the Notes program.
目标:将UIView(一个小放大镜)放置在导航控制器上方。它就像Notes程序中的放大镜一样。
I have partly accomplished this task with the following code:
我用以下代码部分完成了这项任务:
MyAppDelegate *app = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[[[[app navigationController] view] superview] addSubview:_loupe];
This allows the loupe to be displayed above the navigation controller. Note: The _loupe variable contains an instance of a UIView that will magnify the view.
这允许放大镜显示在导航控制器上方。注意:_loupe变量包含将放大视图的UIView实例。
This code works perfectly when in Portrait. When I change the orientation to Landscape, however, the coordinates of the _loupe appear to still be in portrait mode.
此代码在Portrait中完美运行。但是,当我将方向更改为横向时,_loupe的坐标仍显示为纵向模式。
Through lots of trial and error and hours of head banging I realized that the UINavigationController, which is added as the rootViewController of the application, never updates its coordinates when the orientation changes. ALL other views, including the RootViewController (the default class created when creating a new application in XCode) has their coordinates updated.
通过大量的试验和错误以及数小时的头部敲击,我意识到UINavigationController(作为应用程序的rootViewController添加)在方向更改时永远不会更新其坐标。所有其他视图,包括RootViewController(在XCode中创建新应用程序时创建的默认类)都更新了其坐标。
I tried to rectify this by subclassing the UINavigationController with my own controller to make it so the shouldAutorotateToInterfaceOrientation: gets called by the navigation controller instead of the RootViewController. I was hoping that the reason it didn't rotate is because it wasn't the controller requesting the orientation. Nothing.
我试图通过使用我自己的控制器对UINavigationController进行子类化来纠正这个问题,因此导航控制器而不是RootViewController会调用shouldAutorotateToInterfaceOrientation。我希望它不旋转的原因是因为它不是要求定向的控制器。没有。
I've also rotated the _loupe view with the following:
我还使用以下内容旋转_loupe视图:
CGAffineTransform transform = _loupe.transform;
transform = CGAffineTransformMakeRotation([self degreesToRadians:90.0]);
_loupe.transform = transform;
_loupe.bounds = CGRectMake(0, 0, 480, 320);
_loupe.frame = CGRectMake(0, 0, 80, 80);
This makes the UIView, underneath the touch, magnified right side up. Originally, the UIView underneath was rotated -90 when changing the orientation to the left. So I'm almost there... but the coordinates are still screwed up.
这使得触摸下方的UIView正面向上放大。最初,当将方向改为左侧时,下方的UIView旋转-90。所以我差不多......但坐标还是搞砸了。
I've also tried changing the _loupe.bounds to CGRectMake(0, 480, 480, 320) believing that changing the origin might match the underlying coordinate system. No dice.
我也尝试将_loupe.bounds更改为CGRectMake(0,480,480,320),认为更改原点可能与底层坐标系匹配。没有骰子。
My last resort was doing a transform on the actual UITouch x/y points.
我的最后一招是对实际的UITouch x / y点进行转换。
CGPoint point = [touch locationInView:self];
CGAffineTransform transform = CGAffineTransformRotate([_loupe transform], [self degreesToRadians:90.0]);
CGPoint tPoint = CGPointApplyAffineTransform(point, transform);
No dice. However, this does make the loupe displayed near the visible area. What I'm finding is that moving the touch on the x axis moves the loupe on the y axis and moving the touch on the y axis moves the loupe on the x axis. So now it's completely inverted.
没有骰子。但是,这确实使放大镜显示在可见区域附近。我发现的是,在x轴上移动触摸可以在y轴上移动放大镜,在y轴上移动触摸可以在x轴上移动放大镜。所以现在它完全倒转了。
In short, I just want an easy way to display a magnifying glass above the navigation controller without all of this rigmarole.
简而言之,我只是想要一种简单的方法来在导航控制器上方显示放大镜,而不需要这么做。
Edit
I got a little closer by converting the point to the loupe's view.
通过将点转换为放大镜的视图,我得到了一点距离。
CGPoint tPoint = [self convertPoint:point toView:_loupe];
This makes the loupe flicker a lot... it also appears to move the loupe on both the x & y axis (vertically) no matter the direction I move the touch. Getting much closer though!
这使得放大镜闪烁很多......无论我移动触摸的方向如何,它似乎也会在x和y轴(垂直)上移动放大镜。尽可能接近!
1 个解决方案