0
저는 iOS의 새로운 코더입니다. 페이징으로 ScrollView를 코딩하려고 할 때 해결해야 할 문제가 있습니다. 나는 정말로 내 코드에서 어떤 문제인지 모른다. 이미 pageEnable을 설정하고 현재 4 개의 페이지 번호를 0으로 설정합니다. xib.file에서 4 개의보기를 만들었고 scrollview는 "위임자"를 "파일 소유자"에 연결합니다. 내 참조 링크 http://www.iosdevnotes.com/2011/03/uiscrollview-paging/ 앱을 실행할 때보기를 페이징 할 수 없습니다. 도움 주셔서 감사합니다. 내 코드는 다음과 같습니다.PageControl 및 ScrollView 조합
////////// viewDidLoad의 for 루프에 문제가 있다고 생각합니다.
수입
@interface의 ThirdViewController :의 UIViewController {
IBOutlet UIScrollView *scrollView;
IBOutlet UIPageControl *pageControl;
IBOutlet UIView *contentOne;
IBOutlet UIView *contentTwo;
IBOutlet UIView *contentThree;
IBOutlet UIView *contentFour;
}
당신이에 추락 라인 옆에 중단 점을 넣어나요- (IBAction)pageValueChange:(id)sender;
@property(nonatomic,strong) IBOutlet UIScrollView *scrollView;
@property(nonatomic,strong) IBOutlet UIView *contentOne;
@property(nonatomic,strong) IBOutlet UIView *contentTwo;
@property(nonatomic,strong) IBOutlet UIView *contentThree;
@property(nonatomic,strong) IBOutlet UIView *contentFour;
@property(nonatomic,strong) IBOutlet UIPageControl *pageControl;
@property(nonatomic,strong) NSArray *viewArray;
@end
#import "ThirdViewController.h"
@interface ThirdViewController()<UIScrollViewDelegate>
@end
@implementation ThirdViewController
@synthesize scrollView,contentOne, contentTwo,contentThree,contentFour,pageControl,viewArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Profile", @"Third");// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
viewArray = [[NSArray alloc]initWithObjects:@"contentOne",@"contentTwo",@"contentThree", @"contentFour",nil];
for (int i =0; i < [viewArray count]; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i ;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview =[[UIView alloc]initWithFrame:frame];
[self.scrollView addSubview: subview]; //////how to pass the array object to subview
[subview removeFromSuperview];
}
// Do any additional setup after loading the view from its nib.
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width *[viewArray count], scrollView.frame.size.height);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)dismissKeyboard :(id) sender{
[sender resignFirstResponder];
}
- (IBAction)pageValueChange:(id)sender{
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
}
#pragma mark -UIScrollView Delegate
-(void)scrollViewDidScroll:(UIScrollView *)sender{
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1;
self.pageControl.currentPage = page;
}
@end
프로그램 중단시 중단 점을 사용할 수 있습니까? –
코드는 작동하지만 페이지 변경이 작동하지 않습니다. 시뮬레이터를 iPhone 4 인치 망막으로 변경하면 스크롤이 작동하지 않습니다. 나는 이것에 대해 연구 중이다. – HelenWang