devonboyer / DBProfileViewController

A customizable library for creating stunning user profiles.
MIT License
15 stars 3 forks source link

Is it possible to use customized segmented control? #3

Closed Jackson0111 closed 8 years ago

Jackson0111 commented 8 years ago

Hey, thanks for the great work! I was just wondering if it's possible to use a customized segmented control? I'm using DZNSegmentedControl in another project, and I think it would be a great idea to use it here. Is there a way to do that?

devonboyer commented 8 years ago

Unfortunately, there is no way to use a custom control for changing segments as of version 1.0.0.

I am currently working on the next version which will include this feature as well as others. The next version should be released soon. I'll keep you posted on my progress here.

Thanks for bringing this up!

Jackson0111 commented 8 years ago

Thanks for the quick reply! I will definitely be waiting for the new version. But for now I have trouble adding a collection view to content view controllers. I have a view controller that subclasses UICollectionView and UICollectionViewFlowLayout, how should I set up the layout and frame because it keeps giving me an error: 'UICollectionView must be initialized with a non-nil layout parameter'

I'm just a little confused about how to set up a collection view, do you think you can help?

devonboyer commented 8 years ago

That is caused by attempting to instantiate a UICollectionView without giving it a layout.

A collection view must have a layout when initialized, so you must call initWithFrame: collectionViewLayout. You can override init to call this method if you are subclassing UICollectionView if you want.

Note that this problem is unrelated to DBProfileViewController.

Jackson0111 commented 8 years ago

Yes, I understand, I have used collection view before, but I did give it a frame and layout in contentScrollView function. I subclass UICollectionViewFlowLayout and UICollectionViewController, then in contentScrollView I initialized a layout, and set self.collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: flowLayout). But it's still telling me that I need a non-nil parameter layout

devonboyer commented 8 years ago

The contentScrollView is simply a getter for whichever scroll view should be used to track scrolling events for that content view controller. You should not perform any calculations or initializations in this method, as this method gets called very frequently.

-(void)contentScrollView { return self.collectionView; }

Jackson0111 commented 8 years ago

I see! I tried to initialize a collection view will flow layout in viewDidLaod, but it's still giving me the same error... This worked when I just had a UIViewController with a collectionview, but it stopped working when I subclassed UICollectionViewController. Any idea where I can initialize the collection view?

devonboyer commented 8 years ago

UICollectionViewController requires you to call initWithCollectionViewLayout:to instantiate the controller which will take care of initializing the collection view for you.

Jackson0111 commented 8 years ago

I thought I could just do self.collectionView = UICollectionView(frame: collectionViewLayout:) but I guess I can't haha. Thanks for the help! But now I'm having another problem, not sure if this one has something to do with DBProfileViewController. So in my subclass of DBProfileViewController, I also subclass UICollectionViewFlowLayout, and initialized a flowLayout then add the collectionViewController to contentViewControllers like this:

` cellItemSize = CGSizeMake((self.view.frame.width - 20) / 2 - 1, (self.view.frame.width - 20) / 2 + 16)

    let flowLayout = UICollectionViewFlowLayout()

    flowLayout.scrollDirection = .Vertical

    flowLayout.minimumInteritemSpacing = 0

    flowLayout.minimumLineSpacing = 10

    flowLayout.itemSize = cellItemSize!

    flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

    self.addContentViewController(OrdersViewController())

    self.addContentViewController(OngoingSalesViewController(collectionViewLayout: flowLayout))

`

but now when i switch to the second view, something weird happened:

First view: screen shot 2016-03-07 at 7 32 46 pm

Second view: screen shot 2016-03-07 at 7 32 55 pm

And it doesn't matter which view is added first, I tried to switch the order because I thought it might've been something wrong with my collection view, but it doesn't matter, the first view is always fine and the issue appears whenever I tap to switch to the second view.

Jackson0111 commented 8 years ago

Sorry for all the trouble, I've only been doing iOS for half year, still trying to figure out lots of things.

Jackson0111 commented 8 years ago

Ok, I looked at the demo project and finally figured out, the reason was that I didn't set automaticallyAdjustsScrollViewInsets to NO.

devonboyer commented 8 years ago

It is no trouble at all, I have definitely been where you are now!

The requirement to set automaticallyAdjustsScrollViewInsets = NO comes from the fact that when using coverPhotoMimicsNavigationBar we want it to appear underneath the status bar, which is going "against" the default behaviour which is to inset the scroll view to avoid this. Unfortunately things don't look right unless your using that property correctly.

Let me know if you get stuck on anything else. I'm happy to help.

Jackson0111 commented 8 years ago

I really appreciate it! I fixed everything, for now haha. I look forward to the next version, good work!

Jackson0111 commented 8 years ago

Whoops, that didn't last very long lol. I'm using the controller with segue (not navigation controller), and the animation is really slow, looks like UI is blocked for a a couple seconds. Have you encountered this?

devonboyer commented 8 years ago

See the discussion on this issue here https://github.com/DevonBoyer/DBProfileViewController/issues/1

Jackson0111 commented 8 years ago

Yea, I saw that, and I set backgroundColor to whiteColor(), but it didn't change anything.

Jackson0111 commented 8 years ago

I replaced performSegueWithIdentifier("goToPage", sender: nil) with let userAccountVC = UserAccountViewController() userAccountVC.view.backgroundColor = UIColor.whiteColor() self.navigationController?.pushViewController(userAccountVC, animated: true)

but the page didn't even show up, nothing happened. What am I doing wrong...?

devonboyer commented 8 years ago

Is the DBProfileViewController subclass contained in a UINavigationController?

Are you positive the action responder method is getting called?

Jackson0111 commented 8 years ago

Actually, no the DBProfileViewController subclass is not contained in a navigation controller. it's simply just a UIViewController to DBProfileViewController.

devonboyer commented 8 years ago

Then self.navigationController?.pushViewController(userAccountVC, animated: true) should do nothing since self.navigationController is nil.

I recommend using a UINavigationController, check out the demo project on how to configure the controller when doing so.

Jackson0111 commented 8 years ago

My main setup is like snapchat, I use a page view controller to connect three views so users can swipe to switch. The segue to DBProfileViewController is performed from one of the three pages, if I use a navigation controller I don't think I can perform the swipe. Is there a way to work around this?

devonboyer commented 8 years ago

A UIPageViewController simply pages through UIViewController instances. You can simply have one of those view controllers be a UINavigationController (UINavigationController is just a subclass of UIViewController) so that you can push and pop onto it still.

A UINavigationController does not have to be the primary navigation for an app. You can do all sorts of neat things by combining different types of navigations together.

Jackson0111 commented 8 years ago

I'm not sure if I understand you perfectly. So would that be one navigation controller for each view, or just one navigation controller that has three views?

devonboyer commented 8 years ago

You can have a UINavigationController for each page of the UIPageViewController if you want, it's very rare that you don't want to use a navigation controller (since you almost always want to push and pop off a stack).

You can have a UIPageViewController in which each page is a separate instance of UINavigationController. You can simply hide the navigation bar if you don't need it.

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
       viewControllerAfterViewController:(UIViewController *)viewController {
    return [[UINavigationController alloc] initWithRootViewController: [[ProfileViewController alloc] init]];
}
Jackson0111 commented 8 years ago

I started with a UIPageViewController tutorial, and it was just a page view controller with three view controllers. I never thought of using navigation controller actually. I will give it a try! Can I get your help if I get stuck? It's very difficult to learn iOS when literally no one I know knows iOS.

devonboyer commented 8 years ago

There are a lot of tips and tricks you will learn along the way.

You can email me at hello@devonboyer.com if you have any more questions. I'd be happy to help.

Jackson0111 commented 8 years ago

Thank you so much!

devonboyer commented 8 years ago

This issue has been resolved as of version 1.0.1. See the CHANGELOG for more information.

Jackson0111 commented 8 years ago

AWESOME! gonna try it out now

devonboyer commented 8 years ago

The new updates allow you to use a custom subclass of UISegmentedControl. Unfortunately DBProfileViewController is heavily depended on UISegmentedControl, so your custom subclass must inherit from UISegmentedControl.

In FUTURE updates this may be improved to any subclass of UIControl.

Please note that DBProfileViewController now uses the data source pattern, so some methods have been changed/removed to accommodate this. It was not possible to simply deprecate some methods, so changes may be required on your end.

Jackson0111 commented 8 years ago

Does the new version perform better when showing view from a segue?

devonboyer commented 8 years ago

The view should load be able to load a bit faster as of version 1.0.1, so you may see some improvements. Please see the demo project for an example of how to make the appropriate changes to use DBProfileViewControllerDataSource.

Jackson0111 commented 8 years ago

I will, thank you so much!