0
所以我有一个导航控制器,并在其中我有一个视图和滚动视图嵌入在该视图。我的目标是让我的程序在接近它时滚动到某个位置。 做到这一点,我添加到网点,我的VC。一个是滚动视图,另一个是视图。这个视图只是一个大的矩形,大约是iphones屏幕的两倍,稍微高一些。我的滚动视图只能水平滚动,每当我将手指从滚动中提起时,我的目标是如果iPhone的界限在视图范围内。我想滚动视图手动滚动到该视图的中间。 (如果您可以在愤怒的小鸟中想到一个游戏菜单或切断绳子,当用户在水平包间水平滚动时,当用户从滚动滚动到用户放开的位置时,是我想模仿)。有我的导航控制器的代表问题
所以,继承我的代码为我的观点和我的VC。我与故事板做的唯一的事情是,我连接了两个插座,并设置了我的视图的大小。
(关卡包是vc,另一个是视图)。
#import <UIKit/UIKit.h>
#import "HorizantalLockingView.h"
@interface LevelPacks : UIViewController <ViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet HorizantalLockingView *lockingView;
@end
#import "LevelPacks.h"
@implementation LevelPacks
@synthesize scrollView=_scrollView;
@synthesize lockingView = _lockingView;
-(void)viewDidAppear:(BOOL)animated
{
CGSize size;
size.width=825;
size.height=460;
self.scrollView.contentSize=size;
self.scrollView.contentOffset=CGPointMake(0, 0);
}
-(void)viewDidLoad
{
[super viewDidLoad];
self.lockingView.delegate=self;
}
- (void)viewDidUnload
{
[self setLockingView:nil];
[super viewDidUnload];
self.scrollView=nil;
// Release any retained subviews of the main view.
}
@end
#import <UIKit/UIKit.h>
@protocol ViewDelegate
@property (nonatomic, weak) UIScrollView *scrollView;
@end
@interface HorizantalLockingView : UIView
@property (nonatomic, weak) IBOutlet id <ViewDelegate> delegate;
@end
#import "HorizantalLockingView.h"
@implementation HorizantalLockingView
@synthesize delegate=_delegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGRect location=self.superview.bounds;
NSLog(@"dkfjdkjf");
if (CGRectContainsRect(self.frame, location))
{
[self.delegate.scrollView scrollRectToVisible:CGRectMake(284, 190, 157, 119) animated:YES];
}
}
@end
O,和我做了的NSLog早些时候,看是否方法将甚至做任何事情,并且甚至NSLog的绝然,所以很明显出头错误。
我是一个新的这种,任何帮助真的很棒!
这似乎没什么问题(虽然有点从长远看用于粗略IF)。有没有可能'userInteractionEnabled'设置不正确? (另外,你有没有考虑过继承UIScrollview并保存这个委托废话?) – CodaFi 2012-08-02 06:01:59
你刚刚尝试过在滚动视图上启用分页,它会自动执行此操作 – 2012-08-02 07:44:21
@jammycoder酷生病去那条路线! – bmende 2012-08-02 17:31:38