【发布时间】:2013-11-27 22:27:23
【问题描述】:
我有三个视图控制器,它们是 UIScrollView 的一部分。我希望能够在三者之间滑动,尽管其中一个视图控制器具有 UIPanGestureRecognizer。我使用这个平移手势识别器允许用户上下拖动手指来增加和减少矩形 UIView 的高度。因此,这个 UIPanGestureRecognizer 只需要知道向上/向下平移,滚动视图可以使用水平平移。
这方面的一个例子,比如主屏幕;您可以向左或向右滑动,也可以向下滑动以获得聚光灯。我想要这种机制。
这是我的平底锅代码:
- (void)pan:(UIPanGestureRecognizer *)aPan; // When pan guesture is recognised
{
CGPoint location = [aPan locationInView:self.view]; // Location of finger on screen
CGRect secondRect = CGRectMake(210.0, 45.0, 70.0, 325.0); // Rectangles of maximimum bar area
CGRect minuteRect = CGRectMake(125.0, 45.0, 70.0, 325.0);
CGRect hourRect = CGRectMake(41.0, 45.0, 70.0, 325.0);
if (CGRectContainsPoint(secondRect, location)) { // If finger is inside the 'second' rectangle
CGPoint currentPoint = [aPan locationInView:self.view];
currentPoint.y -= 80; // Make sure animation doesn't go outside the bars' rectangle
if (currentPoint.y < 0) {
currentPoint.y = 0;
}
else if (currentPoint.y > 239) {
currentPoint.y = 239;
}
currentPoint.y = 239.0 - currentPoint.y;
CGFloat pointy = currentPoint.y - fmod(currentPoint.y, 4.0);
[UIView animateWithDuration:0.01f // Animate the bars to rise as the finger moves up and down
animations:^{
CGRect oldFrame = secondBar.frame;
secondBar.frame = CGRectMake(oldFrame.origin.x, (oldFrame.origin.y - (pointy - secondBar.frame.size.height)), oldFrame.size.width, (pointy));
}];
CGFloat result = secondBar.frame.size.height - fmod(secondBar.frame.size.height, 4.0);
secondInt = (result / 4.0); // Update labels with new time
self->secondLabel.text = [NSString stringWithFormat:@"%02d", secondInt];
}
代码基本上是针对三个独立的矩形 UIView 重复的。
如果有人能告诉我如何让主屏幕式平移/滑动进入我的应用程序,那就太好了!!
【问题讨论】:
-
您能否分享一个指向您的项目的链接(github/dropbox),以便我看一下?很难说这些条和标签是什么。
-
这里是 DropBox 中整个项目的链接:dropbox.com/sh/9jqry6y2kr5kltr/VklDgKvoYe 希望对您有所帮助!另外,我在将所有三个视图控制器都放入滚动视图时遇到了麻烦,我不确定 ScrollViewController.m 中的代码是否正确,所以如果你也能帮助我解决这个问题,那就太好了!
-
我无法打开该项目。
Bars.xcodeproj文件似乎有问题。 XCode 无法打开它,当我用 TextEdit 打开它时它是空的。 -
是的,那个正在工作。不错的应用程序。让我看看是什么问题,我会回复你
标签: ios objective-c uiscrollview swipe uipangesturerecognizer