这是我要创建的UI
:
以及完整的UI外观:
但是我想创建第一个顶级导航。我尝试过https://github.com/subinspathilettu/SJSegmentedViewController 正在运行,但显示导航后显示SegmentView。有人可以帮助我创建此UI,就像登录后的reddit应用程序屏幕一样。我需要迅速使用。在此先感谢
答案 0 :(得分:0)
好的。这是解决方案。
第1步:
例如:-
@interface ProfileViewController ()<UIScrollViewDelegate>
@property (nonatomic,strong) AboutMeViewController *aboutMeVC;
@property (nonatomic,strong) AddressViewController *addressVC;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_btnAboutMe.selected = NO;
_btnAddress.selected = YES;
_btnPassword.selected = NO;
[self topButtonTapped:_btnAddress]; // This will call the navigation button tap method.
_controllerArray = [@[self.aboutMeVC,self.addressVC,[self.storyboard instantiateViewControllerWithIdentifier:@"changePasswordVC"]] mutableCopy];
[self addChildViewControllersOntoContainer:_controllerArray];
//self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(presentLeftMenuViewController:)];
[_leftBarButton setTarget:self];
[_leftBarButton setAction:@selector(presentLeftMenuViewController:)];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(profileTap:)];
tapGesture.numberOfTapsRequired = 1;
[_profilePicture addGestureRecognizer:tapGesture];
}
-(AboutMeViewController*)aboutMeVC
{
if (!_aboutMeVC) {
_aboutMeVC = [self.storyboard instantiateViewControllerWithIdentifier:@"aboutMeVC"];
}
_aboutMeVC.delegate = self;
return _aboutMeVC;
}
-(AddressViewController*)addressVC
{
if (!_addressVC) {
_addressVC = [self.storyboard instantiateViewControllerWithIdentifier:@"addressVC"];
}
return _addressVC;
}
// Adding all related controllers into the container
-(void) addChildViewControllersOntoContainer:(NSArray *)controllersArr
{
for (int i = 0; i < controllersArr.count; i++)
{
UIViewController *vc = (UIViewController *)[controllersArr objectAtIndex:i];
CGRect frame = CGRectMake(0, 0, self.containerScrollView.frame.size.width, self.containerScrollView.frame.size.height);
frame.origin.x = SCREEN_WIDTH * i;
vc.view.frame = frame;
[self addChildViewController:vc];
[self.containerScrollView addSubview:vc.view];
[vc didMoveToParentViewController:self];
}
self.containerScrollView.contentSize = CGSizeMake(SCREEN_WIDTH * controllersArr.count + 1, self.containerScrollView.frame.size.height - 99);
self.containerScrollView.pagingEnabled = YES;
self.containerScrollView.delegate = self;
}
// Scroll view delegate methods.
// This method will help you to change the navigation by sliding it.
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSInteger page = (scrollView.contentOffset.x / SCREEN_WIDTH);
[self changeButtonState:page];
//_selectedMenu = page;
//_segmentControl.selectedSegmentIndex = page;
NSLog(@"%@", NSStringFromCGSize(scrollView.contentSize));
// float xx = scrollView.contentOffset.x * (buttonWidth / SCREEN_WIDTH) - buttonWidth;
// [self.menuScrollView scrollRectToVisible:CGRectMake(xx, 0, SCREEN_WIDTH, self.menuScrollView.frame.size.height) animated:YES];
}
- (IBAction)topButtonTapped:(UIButton *)sender // Here is the method when you click on top button of your navigation bar.
{
[self changeButtonState:sender.tag];
[self.containerScrollView setContentOffset:CGPointMake(SCREEN_WIDTH * sender.tag, 0) animated:YES];
}
-(void)changeButtonState:(NSInteger)tag
{
if (tag == 0)
{
_btnAboutMe.selected = YES;
_btnAddress.selected = NO;
_btnPassword.selected = NO;
_btnAboutMe.fillColor = [GeneralClass getColorFromHex:kBlueColor withAlpho:1.0];
_btnAddress.fillColor = [GeneralClass getColorFromHex:kWhiteColor withAlpho:1.0];
_btnPassword.fillColor = [GeneralClass getColorFromHex:kWhiteColor withAlpho:1.0];
}
else if (tag == 1)
{
_btnAboutMe.selected = NO;
_btnAddress.selected = YES;
_btnPassword.selected = NO;
_btnAboutMe.fillColor = [GeneralClass getColorFromHex:kWhiteColor withAlpho:1.0];
_btnAddress.fillColor = [GeneralClass getColorFromHex:kBlueColor withAlpho:1.0];
_btnPassword.fillColor = [GeneralClass getColorFromHex:kWhiteColor withAlpho:1.0];
}
else if (tag == 2)
{
_btnAboutMe.selected = NO;
_btnAddress.selected = NO;
_btnPassword.selected = YES;
_btnAboutMe.fillColor = [GeneralClass getColorFromHex:kWhiteColor withAlpho:1.0];
_btnAddress.fillColor = [GeneralClass getColorFromHex:kWhiteColor withAlpho:1.0];
_btnPassword.fillColor = [GeneralClass getColorFromHex:kBlueColor withAlpho:1.0];
}
}
您的ViewController在情节提要中可能看起来像这样。
我希望这会帮助您或至少给您一些想法,以开发您所需的东西。对不起,我在Objective C和一些凌乱的代码中的回答。其实我很着急。但这肯定会帮助您。谢谢! :)
注意:- 请严格按照以下步骤操作。您肯定会找到解决方案。谢谢。 :)