【发布时间】:2014-02-20 17:17:23
【问题描述】:
我有一个从 UIView 类型的类创建的对象,以生成无限数量的视图,然后这些视图以较小的尺寸出现在屏幕中间。我使用 UITapGestureRecognizer 来放大其中一个视图以适应屏幕,但这里的问题是该对象只能在第一类中使用,不能转移到第二类,即选择器。 您对这个特定问题有什么建议? 如何将我的对象发送到选择器以便能够在那里使用它? 谢谢
这是创建对象的第一个类(从 iCarousel 派生):
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
UIButton *close = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 460.0f)];
view.contentMode = UIViewContentModeCenter;
view.backgroundColor = [UIColor whiteColor];
label = [[UILabel alloc] initWithFrame:CGRectMake(100, -100, 100, 100)];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [label.font fontWithSize:50];
label.tag = 1;
[view addSubview:label];
close.frame = CGRectMake(0, 0, 30, 30);
[close setTitle:@"x" forState:UIControlStateNormal];
close.titleLabel.font = [UIFont systemFontOfSize:25];
[close addTarget:self action:@selector(closeMe:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:close];
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToMaximize:)];
tap.numberOfTapsRequired = 1;
[view addGestureRecognizer:tap];
}
else
{
//get a reference to the label in the recycled view
label = (UILabel *)[view viewWithTag:1];
}
label.text = [items[index] stringValue];
return view;
}
还有选择器:
- (void)tapToMaximize:(UITapGestureRecognizer*)recognizer {
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
carousel.transform = CGAffineTransformMakeScale(1, 1);
}
completion:^(BOOL finished) {
}];
}
所以我不想使用代表所有视图的“轮播”,而是使用“视图”,这样我只能放大当前视图而不是所有视图。
【问题讨论】:
-
你能贴出代码来说明你是如何设置的吗?
标签: ios uiview uitapgesturerecognizer