방금 프로젝트 작업을 시작했으며 이미 몇 가지 문제점과 오류가 있습니다. 너희들이 내가 벌레가 어디 있는지 알아낼 수 있는지 궁금해서.버튼이 계속 강조 표시됨
빠른 개요 : 두 개의 파일 (ViewController.m 및 Scroller.m)이 있습니다. ViewController에서 ViewDidLoad (몇 초 후에 보여줄 것입니다) 아래에 몇 가지 코드가 있는데, 나는 또한 그것이 말한 것을 수행하는 함수 (addImagesToView)를 가지고 있으며 touchesBegan, 이동 및 다루기 힘든 것으로 끝났다.
Scroller에서 "- (void) touch"함수 구현 중 일부를 다시 작성하기로 결정했습니다.
문제점 :은 addImagesToView 함수에서 오는 버튼이 강조 표시되어 있습니다. 나는 NSLog로 몇 가지 테스트를 수행하여 어떤 것이 "작동"하고 어떤 것은 작동하지 않는지 확인했습니다. "touchesMoved"가 제대로 작동하지 않습니다. 사용자가 아래로 끌면 약 3 ~ 4 줄의 텍스트가 끝나면 로그가 중지됩니다. 어떻게 든 두루마리를 방해한다고 생각합니다.
이
는 ViewController.m의 내용이다 :- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bgPNG.png"]];
imageView.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:imageView];
//UIColor *background = [[UIColor alloc]initWithPatternImage:imageView.image];
//self.view.backgroundColor = background;
CGRect fullScreen = [[UIScreen mainScreen] applicationFrame];
scroll = [[Scroller alloc] initWithFrame:fullScreen];
scroll.contentSize = CGSizeMake(320, 2730);
scroll.delaysContentTouches = NO;
//scroll.canCancelContentTouches = NO;
scroll.scrollEnabled = YES;
[self.view addSubview:scroll];
buttons = [[NSMutableArray alloc]init];
[self addImagesToView];
}
-(void) addImagesToView{
CGFloat yCoordinate = 35;
for (int i=1; i<=18; i++) {
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"picture%d.png",i]]highlightedImage:[UIImage imageNamed:[NSString stringWithFormat:@"picture%dHG.png",i]]];
CGRect position = CGRectMake(105, yCoordinate, IMAGE_SIZE, IMAGE_SIZE);
image.frame = position;
[scroll addSubview:image];
image.userInteractionEnabled = YES;
image.tag = i;
[buttons addObject:image];
yCoordinate += 150;
}
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Get any touch
UITouch *t = [touches anyObject];
if ([t.view class] == [UIImageView class])
{
// Get the tappedImageView
UIImageView *tappedImageView = (UIImageView*) t.view;
tappedImageView.highlighted = YES;
}
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *t = [touches anyObject];
if ([t.view class] == [UIImageView class])
{
// Get the tappedImageView
UIImageView *tappedImageView = (UIImageView*) t.view;
tappedImageView.highlighted = NO;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources th at can be recreated.
}
@end
이 내가 또한의 ViewController의 모든 접촉을 구현하려고 한 Scroller.m
#import "Scroller.h"
@implementation Scroller
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging)
[self.nextResponder touchesBegan: touches withEvent:event];
else
[super touchesBegan: touches withEvent: event];
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *t = [touches anyObject];
if ([t.view class] == [UIImageView class])
{
// Get the tappedImageView
UIImageView *tappedImageView = (UIImageView*) t.view;
tappedImageView.highlighted = NO;
}
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (!self.dragging)
[self.nextResponder touchesEnded: touches withEvent:event];
else
[super touchesEnded: touches withEvent: event]; // Get the tappedImageView
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
,하지만 난 돈 스크롤에서 읽는 방법을 알지 못합니다 (스크롤과 스크롤러의 차이점에 유의하십시오).
[I] addImagesToView [/ I]에서 나온 이미지가 표시되도록 view -> backGroundImage -> scroller -> addImagesToView (함수)와 같이 주문하려고했습니다. 스크롤 상단 그것은 내 원하는 계층 구조입니다.
대단히 감사합니다.
그래서 UIButton obj를 사용하면 더 잘 작동한다고 생각합니까? 대신 UIImageViews? 내가 만들고자하는 버튼은 사용자 화 된 PNG입니다. – Nactus
예, 버튼을 사용하십시오. 이것은 정확히 설계된 것입니다. – Jim
감사합니다. – Nactus