- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在一个 ViewController 中有 3 个 ViewController
ViewPagerController = self -> 它是一个 viewController 并且有 UIPageViewController init
ProgramQuestionViewController = 它基于 ViewPagerController
QuestionViewController = 我的内容 View 它显示在 ProgramViewController 的中间
这是我的 ViewPagerController
@interface ViewPagerController () <UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIScrollViewDelegate,UIGestureRecognizerDelegate>
{
NSMutableArray *dataAnswers;
}
@property UIScrollView *tabsView;
@property UIView *contentView;
@property UIPageViewController *pageViewController;
@property (assign) id<UIScrollViewDelegate> actualDelegate;
@property (assign)bool isValidPage;
@property (assign)bool isSonraki;
// Tab and content cache
@property NSMutableArray *tabs;
@property NSMutableArray *contents;
// Options
@property (nonatomic) NSNumber *tabHeight;
@property (nonatomic) NSNumber *tabOffset;
@property (nonatomic) NSNumber *tabWidth;
@property (nonatomic) NSNumber *tabLocation;
@property (nonatomic) NSNumber *startFromSecondTab;
@property (nonatomic) NSNumber *centerCurrentTab;
@property (nonatomic) NSNumber *fixFormerTabsPositions;
@property (nonatomic) NSNumber *fixLatterTabsPositions;
@property (nonatomic,retain)UIButton *backButton;
@property (nonatomic,retain)UIButton *nextButton;
@property (nonatomic) NSUInteger tabCount;
@property (nonatomic) NSUInteger activeTabIndex;
@property (nonatomic) NSUInteger activeContentIndex;
@property (getter = isAnimatingToTab, assign) BOOL animatingToTab;
@property (getter = isDefaultSetupDone, assign) BOOL defaultSetupDone;
@property (nonatomic) UIColor *indicatorColor;
@property (nonatomic) UIColor *tabsViewBackgroundColor;
@property (nonatomic) UIColor *contentViewBackgroundColor;
@end
@implementation ViewPagerController
@synthesize tabHeight = _tabHeight;
@synthesize tabOffset = _tabOffset;
@synthesize tabWidth = _tabWidth;
@synthesize tabLocation = _tabLocation;
@synthesize startFromSecondTab = _startFromSecondTab;
@synthesize centerCurrentTab = _centerCurrentTab;
@synthesize fixFormerTabsPositions = _fixFormerTabsPositions;
@synthesize fixLatterTabsPositions = _fixLatterTabsPositions;
@synthesize isValidPage;
@synthesize backButton;
@synthesize nextButton;
@synthesize isSonraki;
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self defaultSettings];
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self defaultSettings];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
isSonraki=false;
isValidPage=true;
dataAnswers =[[NSMutableArray alloc] init];
UIImageView *pagerBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"splash_bg.png"]];
pagerBackground.frame=CGRectMake(0, 800, self.view.frame.size.width, 160);
[self.view setBackgroundColor:[UIColor colorWithRed:234.0/255.0 green:234.0/255.0 blue:234.0/255.0 alpha:0.75]];
backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setFrame:CGRectMake(50, 875, 87, 45)];
[backButton setBackgroundImage:[UIImage imageNamed:@"prev_btn.png"] forState:UIControlStateNormal];
//UITapGestureRecognizer *tapGestureRecognizerBack = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBackTapGesture:)];
//[backButton addGestureRecognizer:tapGestureRecognizerBack];
[backButton addTarget:self action:@selector(handleBackTapGesture:) forControlEvents:UIControlEventTouchUpInside];
backButton.hidden=YES;
nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
[nextButton setFrame:CGRectMake(620, 875, 87, 45)];
[nextButton setBackgroundImage:[UIImage imageNamed:@"next_btn.png"] forState:UIControlStateNormal];
//UITapGestureRecognizer *tapGestureRecognizerNext = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleNextTapGesture:)];
//[nextButton addGestureRecognizer:tapGestureRecognizerNext];
[nextButton addTarget:self action:@selector(handleNextTapGesture:) forControlEvents:UIControlEventTouchUpInside];
for (UIGestureRecognizer *gr in [self.pageViewController gestureRecognizers]) {
[gr setEnabled:NO];
}
[self.view addSubview:nextButton];
[self.view addSubview:backButton];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
//Touch gestures below top bar should not make the page turn.
//EDITED Check for only Tap here instead.
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
CGPoint touchPoint = [touch locationInView:self.view];
if (touchPoint.y > 40) {
return NO;
}
else if (touchPoint.x > 50 && touchPoint.x < 430) {//Let the buttons in the middle of the top bar receive the touch
return NO;
}
}
return YES;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Do setup if it's not done yet
if (![self isDefaultSetupDone]) {
[self defaultSetup];
NSLog(@"hello");
}
}
- (void)viewWillLayoutSubviews {
// Re-layout sub views
[self layoutSubviews];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)layoutSubviews {
CGFloat topLayoutGuide = 0.0;
CGRect frame = self.tabsView.frame;
frame.origin.x = 150.0;
frame.origin.y = [self.tabLocation boolValue] ? topLayoutGuide : CGRectGetHeight(self.view.frame) - [self.tabHeight floatValue];
frame.size.width = 450;//CGRectGetWidth(self.view.frame);
frame.size.height = [self.tabHeight floatValue];
self.tabsView.frame = frame;
frame = self.contentView.frame;
frame.origin.x = 0.0;
frame.origin.y = [self.tabLocation boolValue] ? topLayoutGuide + CGRectGetHeight(self.tabsView.frame) : topLayoutGuide;
frame.size.width = CGRectGetWidth(self.view.frame);
frame.size.height = CGRectGetHeight(self.view.frame) - (topLayoutGuide + CGRectGetHeight(self.tabsView.frame)) - CGRectGetHeight(self.tabBarController.tabBar.frame);
self.contentView.frame = frame;
}
- (IBAction)handleTapGesture:(id)sender {
}
- (IBAction)handleNextTapGesture:(id)sender {
//UIView *myvview=[self.dataSource viewPager:self contentViewForTabAtIndex:0];
//backButton.hidden=NO;
UIViewController *viewController = [self.dataSource viewPager:self contentViewControllerForTabAtIndex:_activeContentIndex];
UIViewController *xvc=[LoggedinUser sharedCenter].myQuestionView;
[self saveMyData:xvc];
if (isValidPage) {
[self selectTabAtIndex:self.activeContentIndex+1];
}
}
- (IBAction)handleBackTapGesture:(id)sender {
if(self.activeTabIndex==0)
{
backButton.hidden=YES;
}
else
{
backButton.hidden=NO;
}
UIViewController *viewController = [self.dataSource viewPager:self contentViewControllerForTabAtIndex:_activeContentIndex];
UIViewController *xvc=[LoggedinUser sharedCenter].myQuestionView;
[self saveMyData:xvc];
if (isValidPage) {
[self selectTabAtIndex:self.activeContentIndex-1];
}
}
- (void)setActiveTabIndex:(NSUInteger)activeTabIndex {
TabView *activeTabView;
// Set to-be-inactive tab unselected
activeTabView = [self tabViewAtIndex:self.activeTabIndex];
activeTabView.selected = NO;
// Set to-be-active tab selected
activeTabView = [self tabViewAtIndex:activeTabIndex];
activeTabView.selected = YES;
// Set current activeTabIndex
_activeTabIndex = activeTabIndex;
// Bring tab to active position
// Position the tab in center if centerCurrentTab option is provided as YES
UIView *tabView = [self tabViewAtIndex:self.activeTabIndex];
CGRect frame = tabView.frame;
if ([self.centerCurrentTab boolValue]) {
frame.origin.x += (CGRectGetWidth(frame) / 2);
frame.origin.x -= CGRectGetWidth(self.tabsView.frame) / 2;
frame.size.width = CGRectGetWidth(self.tabsView.frame);
if (frame.origin.x < 0) {
frame.origin.x = 0;
}
if ((frame.origin.x + CGRectGetWidth(frame)) > self.tabsView.contentSize.width) {
frame.origin.x = (self.tabsView.contentSize.width - CGRectGetWidth(self.tabsView.frame));
}
} else {
//frame.origin.x -= [self.tabOffset floatValue];
frame.origin.x -= [self.tabOffset floatValue];
frame.size.width = CGRectGetWidth(self.tabsView.frame);
}
[self.tabsView scrollRectToVisible:frame animated:YES];
}
- (void)setActiveContentIndex:(NSUInteger)activeContentIndex {
// Get the desired viewController
UIViewController *viewController = [self viewControllerAtIndex:activeContentIndex];
if (!viewController) {
viewController = [[UIViewController alloc] init];
viewController.view = [[UIView alloc] init];
viewController.view.backgroundColor = [UIColor clearColor];
}
// __weak pageViewController to be used in blocks to prevent retaining strong reference to self
__weak UIPageViewController *weakPageViewController = self.pageViewController;
__weak ViewPagerController *weakSelf = self;
if (activeContentIndex == self.activeContentIndex) {
[self.pageViewController setViewControllers:@[viewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:^(BOOL completed) {
weakSelf.animatingToTab = NO;
}];
} else if (!(activeContentIndex + 1 == self.activeContentIndex || activeContentIndex - 1 == self.activeContentIndex)) {
[self.pageViewController setViewControllers:@[viewController]
direction:(activeContentIndex < self.activeContentIndex) ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward
animated:YES
completion:^(BOOL completed) {
weakSelf.animatingToTab = NO;
// Set the current page again to obtain synchronisation between tabs and content
dispatch_async(dispatch_get_main_queue(), ^{
[weakPageViewController setViewControllers:@[viewController]
direction:(activeContentIndex < weakSelf.activeContentIndex) ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
});
}];
} else {
[self.pageViewController setViewControllers:@[viewController]
direction:(activeContentIndex < self.activeContentIndex) ? UIPageViewControllerNavigationDirectionReverse : UIPageViewControllerNavigationDirectionForward
animated:YES
completion:^(BOOL completed) {
weakSelf.animatingToTab = NO;
}];
}
// Clean out of sight contents
NSInteger index;
index = self.activeContentIndex - 1;
if (index >= 0 &&
index != activeContentIndex &&
index != activeContentIndex - 1)
{
[self.contents replaceObjectAtIndex:index withObject:[NSNull null]];
}
index = self.activeContentIndex;
if (index != activeContentIndex - 1 &&
index != activeContentIndex &&
index != activeContentIndex + 1)
{
[self.contents replaceObjectAtIndex:index withObject:[NSNull null]];
}
index = self.activeContentIndex + 1;
if (index < self.contents.count &&
index != activeContentIndex &&
index != activeContentIndex + 1)
{
[self.contents replaceObjectAtIndex:index withObject:[NSNull null]];
}
_activeContentIndex = activeContentIndex;
}
- (void)reloadData {
// Empty all options and colors
// So that, ViewPager will reflect the changes
// Empty all options
_tabHeight = nil;
_tabOffset = nil;
_tabWidth = nil;
_tabLocation = nil;
_startFromSecondTab = nil;
_centerCurrentTab = nil;
_fixFormerTabsPositions = nil;
_fixLatterTabsPositions = nil;
// Empty all colors
_indicatorColor = nil;
_tabsViewBackgroundColor = nil;
_contentViewBackgroundColor = nil;
// Call to setup again with the updated data
[self defaultSetup];
}
- (void)selectTabAtIndex:(NSUInteger)index {
if (index >= self.tabCount) {
return;
}
self.animatingToTab = YES;
// Set activeTabIndex
self.activeTabIndex = index;
// Set activeContentIndex
self.activeContentIndex = index;
// Inform delegate about the change
if ([self.delegate respondsToSelector:@selector(viewPager:didChangeTabToIndex:)]) {
[self.delegate viewPager:self didChangeTabToIndex:self.activeTabIndex];
}
}
- (void)setNeedsReloadOptions {
// If our delegate doesn't respond to our options method, return
// Otherwise reload options
if (![self.delegate respondsToSelector:@selector(viewPager:valueForOption:withDefault:)]) {
return;
}
// Update these options
self.tabWidth = [NSNumber numberWithFloat:[self.delegate viewPager:self valueForOption:ViewPagerOptionTabWidth withDefault:kTabWidth]];
self.tabOffset = [NSNumber numberWithFloat:[self.delegate viewPager:self valueForOption:ViewPagerOptionTabOffset withDefault:kTabOffset]];
self.centerCurrentTab = [NSNumber numberWithFloat:[self.delegate viewPager:self valueForOption:ViewPagerOptionCenterCurrentTab withDefault:kCenterCurrentTab]];
self.fixFormerTabsPositions = [NSNumber numberWithFloat:[self.delegate viewPager:self valueForOption:ViewPagerOptionFixFormerTabsPositions withDefault:kFixFormerTabsPositions]];
self.fixLatterTabsPositions = [NSNumber numberWithFloat:[self.delegate viewPager:self valueForOption:ViewPagerOptionFixLatterTabsPositions withDefault:kFixLatterTabsPositions]];
// We should update contentSize property of our tabsView, so we should recalculate it with the new values
CGFloat contentSizeWidth = 0;
// Give the standard offset if fixFormerTabsPositions is provided as YES
if ([self.fixFormerTabsPositions boolValue]) {
// And if the centerCurrentTab is provided as YES fine tune the offset according to it
if ([self.centerCurrentTab boolValue]) {
contentSizeWidth = (CGRectGetWidth(self.tabsView.frame) - [self.tabWidth floatValue]) / 2.0;
} else {
contentSizeWidth = [self.tabOffset floatValue];
}
}
// Update every tab's frame
for (NSUInteger i = 0; i < self.tabCount; i++) {
UIView *tabView = [self tabViewAtIndex:i];
CGRect frame = tabView.frame;
frame.origin.x = contentSizeWidth;
frame.size.width = [self.tabWidth floatValue];
tabView.frame = frame;
contentSizeWidth += CGRectGetWidth(tabView.frame);
}
// Extend contentSizeWidth if fixLatterTabsPositions is provided YES
if ([self.fixLatterTabsPositions boolValue]) {
// And if the centerCurrentTab is provided as YES fine tune the content size according to it
if ([self.centerCurrentTab boolValue]) {
contentSizeWidth += (CGRectGetWidth(self.tabsView.frame) - [self.tabWidth floatValue]) / 2.0;
} else {
contentSizeWidth += CGRectGetWidth(self.tabsView.frame) - [self.tabWidth floatValue] - [self.tabOffset floatValue];
}
}
// Update tabsView's contentSize with the new width
self.tabsView.contentSize = CGSizeMake(contentSizeWidth, [self.tabHeight floatValue]);
}
- (void)setNeedsReloadColors {
// If our delegate doesn't respond to our colors method, return
// Otherwise reload colors
if (![self.delegate respondsToSelector:@selector(viewPager:colorForComponent:withDefault:)]) {
return;
}
// These colors will be updated
UIColor *indicatorColor;
UIColor *tabsViewBackgroundColor;
UIColor *contentViewBackgroundColor;
// Get indicatorColor and check if it is different from the current one
// If it is, update it
indicatorColor = [self.delegate viewPager:self colorForComponent:ViewPagerIndicator withDefault:kIndicatorColor];
if (![self.indicatorColor isEqualToColor:indicatorColor]) {
// We will iterate through all of the tabs to update its indicatorColor
[self.tabs enumerateObjectsUsingBlock:^(TabView *tabView, NSUInteger index, BOOL *stop) {
tabView.indicatorColor = indicatorColor;
}];
// Update indicatorColor to check again later
self.indicatorColor = indicatorColor;
}
// Get tabsViewBackgroundColor and check if it is different from the current one
// If it is, update it
tabsViewBackgroundColor = [self.delegate viewPager:self colorForComponent:ViewPagerTabsView withDefault:kTabsViewBackgroundColor];
if (![self.tabsViewBackgroundColor isEqualToColor:tabsViewBackgroundColor]) {
// Update it
self.tabsView.backgroundColor = tabsViewBackgroundColor;
// Update tabsViewBackgroundColor to check again later
self.tabsViewBackgroundColor = tabsViewBackgroundColor;
}
// Get contentViewBackgroundColor and check if it is different from the current one
// Yeah update it, too
//contentViewBackgroundColor = [self.delegate viewPager:self colorForComponent:ViewPagerContent withDefault:kContentViewBackgroundColor];
//if (![self.contentViewBackgroundColor isEqualToColor:contentViewBackgroundColor]) {
// Yup, update
// self.contentView.backgroundColor = contentViewBackgroundColor;
// Update this, too, to check again later
// self.contentViewBackgroundColor = contentViewBackgroundColor;
//}
}
- (CGFloat)valueForOption:(ViewPagerOption)option {
switch (option) {
case ViewPagerOptionTabHeight:
return [[self tabHeight] floatValue];
case ViewPagerOptionTabOffset:
return [[self tabOffset] floatValue];
case ViewPagerOptionTabWidth:
return [[self tabWidth] floatValue];
case ViewPagerOptionTabLocation:
return [[self tabLocation] floatValue];
case ViewPagerOptionStartFromSecondTab:
return [[self startFromSecondTab] floatValue];
case ViewPagerOptionCenterCurrentTab:
return [[self centerCurrentTab] floatValue];
default:
return NAN;
}
}
-(void)setScrollEnabled:(BOOL)enabled forPageViewController:(UIPageViewController*)pageViewController{
for(UIView* view in pageViewController.view.subviews){
if([view isKindOfClass:[UIScrollView class]]){
UIScrollView* scrollView=(UIScrollView*)view;
[scrollView setScrollEnabled:enabled];
return;
}
}
}
- (void)defaultSettings {
// pageViewController
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
[self addChildViewController:self.pageViewController];
// Setup some forwarding events to hijack the scrollView
// Keep a reference to the actual delegate
self.actualDelegate = ((UIScrollView *)[self.pageViewController.view.subviews objectAtIndex:0]).delegate;
// Set self as new delegate
((UIScrollView *)[self.pageViewController.view.subviews objectAtIndex:0]).delegate = self;
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
self.animatingToTab = NO;
self.defaultSetupDone = NO;
}
- (void)defaultSetup {
// Empty tabs and contents
for (UIView *tabView in self.tabs) {
[tabView removeFromSuperview];
}
self.tabsView.contentSize = CGSizeZero;
[self.tabs removeAllObjects];
[self.contents removeAllObjects];
// Get tabCount from dataSource
self.tabCount = [self.dataSource numberOfTabsForViewPager:self];
// Populate arrays with [NSNull null];
self.tabs = [NSMutableArray arrayWithCapacity:self.tabCount];
for (NSUInteger i = 0; i < self.tabCount; i++) {
[self.tabs addObject:[NSNull null]];
}
self.contents = [NSMutableArray arrayWithCapacity:self.tabCount];
for (NSUInteger i = 0; i < self.tabCount; i++) {
[self.contents addObject:[NSNull null]];
}
// Add tabsView
self.tabsView = (UIScrollView *)[self.view viewWithTag:kTabViewTag];
if (!self.tabsView) {
self.tabsView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.view.frame), [self.tabHeight floatValue])];
self.tabsView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.tabsView.backgroundColor = self.tabsViewBackgroundColor;
self.tabsView.scrollsToTop = NO;
self.tabsView.showsHorizontalScrollIndicator = NO;
self.tabsView.showsVerticalScrollIndicator = NO;
self.tabsView.tag = kTabViewTag;
[self.view insertSubview:self.tabsView atIndex:0];
}
// Add tab views to _tabsView
CGFloat contentSizeWidth = 0;
// Give the standard offset if fixFormerTabsPositions is provided as YES
if ([self.fixFormerTabsPositions boolValue]) {
// And if the centerCurrentTab is provided as YES fine tune the offset according to it
if ([self.centerCurrentTab boolValue]) {
contentSizeWidth = (CGRectGetWidth(self.tabsView.frame) - [self.tabWidth floatValue]) / 2.0;
} else {
contentSizeWidth = [self.tabOffset floatValue];
}
}
for (NSUInteger i = 0; i < self.tabCount; i++) {
UIView *tabView = [self tabViewAtIndex:i];
CGRect frame = tabView.frame;
frame.origin.x = contentSizeWidth;
frame.size.width = [self.tabWidth floatValue];
tabView.frame = frame;
[self.tabsView addSubview:tabView];
contentSizeWidth += CGRectGetWidth(tabView.frame);
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
[tabView addGestureRecognizer:tapGestureRecognizer];
}
contentSizeWidth=contentSizeWidth-500;
if ([self.fixLatterTabsPositions boolValue]) {
if ([self.centerCurrentTab boolValue]) {
contentSizeWidth += (CGRectGetWidth(self.tabsView.frame) - [self.tabWidth floatValue]) / 2.0;
} else {
contentSizeWidth += CGRectGetWidth(self.tabsView.frame) - [self.tabWidth floatValue] - [self.tabOffset floatValue];
}
}
self.tabsView.contentSize = CGSizeMake(contentSizeWidth, [self.tabHeight floatValue]);
self.contentView = [self.view viewWithTag:kContentViewTag];
if (!self.contentView) {
self.contentView = self.pageViewController.view;
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
// self.contentView.backgroundColor = self.contentViewBackgroundColor;
self.contentView.bounds = self.view.bounds;
self.contentView.tag = kContentViewTag;
[self.view insertSubview:self.contentView atIndex:0];
}
NSUInteger index = [self.startFromSecondTab boolValue] ? 1 : 0;
[self selectTabAtIndex:index];
self.defaultSetupDone = YES;
}
- (TabView *)tabViewAtIndex:(NSUInteger)index {
if (index >= self.tabCount) {
return nil;
}
if ([[self.tabs objectAtIndex:index] isEqual:[NSNull null]]) {
UIView *tabViewContent = [self.dataSource viewPager:self viewForTabAtIndex:index];
tabViewContent.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
TabView *tabView = [[TabView alloc] initWithFrame:CGRectMake(0.0, 0.0, [self.tabWidth floatValue], [self.tabHeight floatValue])];
[tabView addSubview:tabViewContent];
[tabView setClipsToBounds:YES];
[tabView setIndicatorColor:self.indicatorColor];
tabViewContent.center = tabView.center;
// Replace the null object with tabView
[self.tabs replaceObjectAtIndex:index withObject:tabView];
}
return [self.tabs objectAtIndex:index];
}
- (UIViewController *)viewControllerAtIndex:(NSUInteger)index {
if (index >= self.tabCount) {
return nil;
}
if ([[self.contents objectAtIndex:index] isEqual:[NSNull null]]) {
UIViewController *viewController;
if ([self.dataSource respondsToSelector:@selector(viewPager:contentViewControllerForTabAtIndex:)]) {
viewController = [self.dataSource viewPager:self contentViewControllerForTabAtIndex:index];
} else if ([self.dataSource respondsToSelector:@selector(viewPager:contentViewForTabAtIndex:)]) {
UIView *view = [self.dataSource viewPager:self contentViewForTabAtIndex:index];
// Adjust view's bounds to match the pageView's bounds
UIView *pageView = [self.view viewWithTag:kContentViewTag];
view.frame = pageView.bounds;
viewController = [UIViewController new];
viewController.view = view;
} else {
viewController = [[UIViewController alloc] init];
viewController.view = [[UIView alloc] init];
}
[self.contents replaceObjectAtIndex:index withObject:viewController];
}
return [self.contents objectAtIndex:index];
}
- (NSUInteger)indexForViewController:(UIViewController *)viewController {
return [self.contents indexOfObject:viewController];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [self indexForViewController:viewController];
index++;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [self indexForViewController:viewController];
index--;
return [self viewControllerAtIndex:index];
}
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
UIViewController *viewController = self.pageViewController.viewControllers[0];
// Select tab
NSUInteger index = [self indexForViewController:viewController];
[self selectTabAtIndex:index];
}
我不想在这个 pageviewController 上滑动我只想处理下一个和后退按钮的分页,但我不能禁用滑动手势。是否可以禁用它或者是否有其他方法可以删除该 View 中的所有手势?
最佳答案
这样试试
for (UIScrollView *view in self.pageViewController.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.scrollEnabled = NO;
}
}
关于ios - 在 UIPageViewController 中禁用滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25360016/
IO 设备如何知道属于它的内存中的值在memory mapped IO 中发生了变化? ? 例如,假设内存地址 0 专用于保存 VGA 设备的背景颜色。当我们更改 memory[0] 中的值时,VGA
我目前正在开发一个使用Facebook sdk登录(通过FBLoginView)的iOS应用。 一切正常,除了那些拥有较旧版本的facebook的人。 当他们按下“使用Facebook登录”按钮时,他
假设我有: this - is an - example - with some - dashesNSRange将使用`rangeOfString:@“-”拾取“-”的第一个实例,但是如果我只想要最后
Card.io SDK提供以下详细信息: 卡号,有效期,月份,年份,CVV和邮政编码。 如何从此SDK获取国家名称。 - (void)userDidProvideCreditCardInfo:(Car
iOS 应用程序如何从网络服务下载图片并在安装过程中将它们安装到用户的 iOS 设备上?可能吗? 最佳答案 您无法控制应用在用户设备上的安装,因此无法在安装过程中下载其他数据。 只需在安装后首次启动应
我曾经开发过一款企业版 iOS 产品,我们公司曾将其出售给大型企业,供他们的员工使用。 该应用程序通过 AppStore 提供,企业用户获得了公司特定的配置文件(包含应用程序配置文件)以启用他们有权使
我正在尝试将 Card.io SDK 集成到我的 iOS 应用程序中。我想为 CardIO ui 做一个简单的本地化,如更改取消按钮标题或“在此保留信用卡”提示文本。 我在 github 上找到了这个
我正在使用 CardIOView 和 CardIOViewDelegate 类,没有可以设置为 YES 的 BOOL 来扫描 collectCardholderName。我可以看到它在 CardIOP
我有一个集成了通话工具包的 voip 应用程序。每次我从我的 voip 应用程序调用时,都会在 native 电话应用程序中创建一个新的最近通话记录。我在 voip 应用程序中也有自定义联系人(电话应
iOS 应用程序如何知道应用程序打开时屏幕上是否已经有键盘?应用程序运行后,它可以接收键盘显示/隐藏通知。但是,如果应用程序在分屏模式下作为辅助应用程序打开,而主应用程序已经显示键盘,则辅助应用程序不
我在模拟器中收到以下错误: ImageIO: CGImageReadSessionGetCachedImageBlockData *** CGImageReadSessionGetCachedIm
如 Apple 文档所示,可以通过 EAAccessory Framework 与经过认证的配件(由 Apple 认证)进行通信。但是我有点困惑,因为一些帖子告诉我它也可以通过 CoreBluetoo
尽管现在的调试器已经很不错了,但有时找出应用程序中正在发生的事情的最好方法仍然是古老的 NSLog。当您连接到计算机时,这样做很容易; Xcode 会帮助弹出日志查看器面板,然后就可以了。当您不在办公
在我的 iOS 应用程序中,我定义了一些兴趣点。其中一些有一个 Kontakt.io 信标的名称,它绑定(bind)到一个特定的 PoI(我的意思是通常贴在信标标签上的名称)。现在我想在附近发现信标,
我正在为警报提示创建一个 trigger.io 插件。尝试从警报提示返回数据。这是我的代码: // Prompt + (void)show_prompt:(ForgeTask*)task{
您好,我是 Apple iOS 的新手。我阅读并搜索了很多关于推送通知的文章,但我没有发现任何关于 APNS 从 io4 到 ios 6 的新更新的信息。任何人都可以向我提供 APNS 如何在 ios
UITabBar 的高度似乎在 iOS 7 和 8/9/10/11 之间发生了变化。我发布这个问题是为了让其他人轻松找到答案。 那么:在 iPhone 和 iPad 上的 iOS 8/9/10/11
我想我可以针对不同的 iOS 版本使用不同的 Storyboard。 由于 UI 的差异,我将创建下一个 Storyboard: Main_iPhone.storyboard Main_iPad.st
我正在写一些东西,我将使用设备的 iTunes 库中的一部分音轨来覆盖 2 个视频的组合,例如: AVMutableComposition* mixComposition = [[AVMutableC
我创建了一个简单的 iOS 程序,可以顺利编译并在 iPad 模拟器上运行良好。当我告诉 XCode 4 使用我连接的 iPad 设备时,无法编译相同的程序。问题似乎是当我尝试使用附加的 iPad 时
我是一名优秀的程序员,十分优秀!