Code Monkey home page Code Monkey logo

mgspotyviewcontroller's Introduction

MGSpotyViewController

Beautiful viewController with a tableView and amazing effects like a viewController in the Spotify app. With MGSpotyViewController you can implement several layouts like these:

MGSpotyViewController Gif

MGSpotyViewController Gif

MGSpotyViewController Gif

Info

This code must be used under ARC. If your code doesn't use ARC you can mark this source with the compiler flag -fobjc-arc

Example Usage

In the package is included an example to use this class.

The best thing to do, is to extend the MGSpotyViewController. In the package see the class MGViewController.{h,m} as example.

Here the explanation:

Init is easy. You have just to pass the main image for the blur effect:

MGViewController *spotyViewController = [[MGViewController alloc] initWithMainImage:[UIImage imageNamed:@"example"]];

MGViewController extends MGSpotyViewController:

//
//  MGViewController.h
//  MGSpotyView
//
//  Created by Matteo Gobbi on 25/06/2014.
//  Copyright (c) 2014 Matteo Gobbi. All rights reserved.
//

#import "MGSpotyViewController.h"

@interface MGViewController : MGSpotyViewController


@end

Set the delegate and the datasource of the MGSpotyViewController:

- (instancetype)init
{
    if (self = [super init]) {
        self.dataSource = myDataSource; //Or self
        self.delegate = myDelegate; //Or self
    }
    
    return self;
}

In the implementation file, first of all you should set the overView. The overView is basically the header view which remains over the blur image:

- (void)viewDidLoad {
    [self setOverView:self.myOverView];
}


//This is just an example view created by code, but you can return any type of view.
- (UIView *)myOverView {
    UIView *view = [[UIView alloc] initWithFrame:self.overView.bounds];

    //Add an example imageView
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(view.center.x-50.0, view.center.y-60.0, 100.0, 100.0)];
    [imageView setContentMode:UIViewContentModeScaleAspectFill];
    [imageView setClipsToBounds:YES];
    [imageView setImage:[UIImage imageNamed:@"example"]];
    [imageView.layer setBorderColor:[UIColor whiteColor].CGColor];
    [imageView.layer setBorderWidth:2.0];
    [imageView.layer setCornerRadius:imageView.frame.size.width/2.0];

    //Add an example label
    UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(view.center.x-120.0, view.center.y+50.0, 240.0, 50.0)];
    [lblTitle setText:@"Name Surname"];
    [lblTitle setFont:[UIFont boldSystemFontOfSize:25.0]];
    [lblTitle setTextAlignment:NSTextAlignmentCenter];
    [lblTitle setTextColor:[UIColor whiteColor]];


    [view addSubview:imageView];
    [view addSubview:lblTitle];

    return view;
}

Another thing to configure is the tableView. The tableView is already in the MGSpotyViewController, you have just to set the MGSpotyViewControllerDataSource and MGSpotyViewControllerDelegate and use their methods.

You must remember that the section 0 is reserved, so even if you will return 1 section, your delegate will get called for section number 1, not 0. Basically for sections the counter doesn't start from 0 but from 1:

#pragma mark - MGSpotyViewControllerDataSource

- (NSInteger)numberOfSectionsInSpotyViewController:(MGSpotyViewController *)spotyViewController
{
    return 1;
}

- (NSInteger)spotyViewController:(MGSpotyViewController *)spotyViewController
       numberOfRowsInSection:(NSInteger)section
{
  return 20;
}

- (UITableViewCell *)spotyViewController:(MGSpotyViewController *)spotyViewController
                               tableView:(UITableView *)tableView
                   cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  // IndexPath is 1-1, 1-2, 1-3 etc.
  
  UITableViewCell *cell = // Your cell initialisation

  return cell;
}

And, if you need to manage sections header title or sections header view:

#pragma mark - MGSpotyViewControllerDelegate

- (CGFloat)spotyViewController:(MGSpotyViewController *)spotyViewController
  heightForHeaderInSection:(NSInteger)section
{
  return 20.0;
}

- (NSString *)spotyViewController:(MGSpotyViewController *)spotyViewController
      titleForHeaderInSection:(NSInteger)section
{
  return @"My Section";
}

Customisations

There are a bunch of properties you can play with to get the best result for your needs:

/**
 *  The tint color on top of the blur. When alpha is 1.0 
 *  you'll not be able to see the image behind.
 */
@property (nonatomic, strong) UIColor *tintColor;

/**
 *  Indicate if the overView has to fade out when scrolling up
 *  Default value: NO
 */
@property (atomic) BOOL overViewFadeOut;

/**
 *  Indicate if the main image has to get unblurred when scrolling down
 *  Default value: YES
 */
@property (atomic) BOOL shouldUnblur;

/**
 *  Indicate if the overView height is resized automatically when the
 *  device is rotated (ie when the height of the interface change)
 *  Default value: YES
 */
@property (atomic) BOOL flexibleOverviewHeight;

/**
 *  Set the value of the blur radius.
 *  Default value: 20.0
 */
@property (nonatomic) CGFloat blurRadius;

And also an initialiser which takes in input a scrolling type which are essentially the 2 kinds of scrolling you see in the previous examples:

- (instancetype)initWithMainImage:(UIImage *)image tableScrollingType:(MGSpotyViewTableScrollingType)scrollingType;

Contact

Matteo Gobbi

License

MGSpotyViewController is available under the MIT license.

mgspotyviewcontroller's People

Contributors

danielebogo avatar rickerbh avatar solomonbier avatar yuriferretti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mgspotyviewcontroller's Issues

Grouped Style

Heyo

Awesome Project !!!
Can I somehow change the TableViewStyle to grouped instead of plain ? Was messing around with the code but didn't get any results.

Cheers
Philipp

table view with zero rows or fulscreen image view

I want a small table view (2 rows) or just not table view with small circular image in middle and the enlarged blurred image in background and the scroll effect enabled. Also I dont want the scroll up effect. Can you tell how do I do that? I tried setting the number of rows in table view to 2 but it looks bad. I did set the small circular image view in middle. I'm no getting how do I set the image of mainImageView to be enlarged and covering nearly entire screen.

Scroll events in overView

As in the current version, the touch events in overView are sent using hitTest function to respective selectors. I want to implement that scroll events on overView also leads to scrollViewdidScroll and show blur effect but preserving button press events. I did this in previous version where parent view was simple view and not MGSpotyView.
Any ideas as to how to implement this?

Selectors for buttons added to myOverView never get called?

Selectors for buttons added to myOverView never get called? Could you please provide an example button?

UIButton *twitterButton = [UIButton buttonWithType:UIButtonTypeCustom];
[twitterButton setTitle:twitterString forState:UIControlStateNormal];
[twitterButton addTarget:self action:@selector(hello:) forControlEvents:UIControlEventTouchUpInside];
twitterButton.frame = CGRectMake(50, 50, twitterLabelSize.width, 30.0);
[twitterButton setBackgroundColor:[UIColor clearColor]];
[twitterButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[twitterButton setTitleShadowColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[twitterButton setTitleEdgeInsets:UIEdgeInsetsMake( -4.0f, 0.0f, 0.0f, 0.0f)];
[[twitterButton titleLabel] setShadowOffset:CGSizeMake( 0.0f, 0.5f)];
[[twitterButton titleLabel] setFont:[UIFont fontWithName:@"Avenir-Medium" size:14.0f]];
[[twitterButton titleLabel] setMinimumScaleFactor:0.8f];
[[twitterButton titleLabel] setAdjustsFontSizeToFitWidth:YES];
[[twitterButton titleLabel] setTextAlignment:NSTextAlignmentLeft];
[twitterButton setSelected:NO];
twitterButton.userInteractionEnabled = YES;
[twitterButton setClipsToBounds:YES];
[view addSubview:twitterButton];

- (void) hello:(id) sender  { 
    NSLog(@"helloooo"); 
}

Support for UITableViewStyleGrouped and changing mainImage

At the moment, MGSpotyViewController doesn't handle UITableViewStyleGrouped very well, allowing the backing view to be visible alongside the overView behind the cells (especially when scrolling). Also, there's no way to properly change the mainImageView image after its initial setup (the image backing is not visible from other classes). This means there's no way to "lazy load" imagery and prevent lengthy delays if the main image needs to be pulled from the server. Love the utility besides these drawbacks! I'm sure they'd be solved by simply using header-declared properties instead of ivars.

Let me know if you have any plans to resolve these issues, or if you wouldn't mind me submitting a pull request for them myself :)

Add iOS8 Blur support

support native blur Visual effect provided by iOS8

    UIVisualEffect *blurEffect;
    blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *visualEffectView;
    visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    visualEffectView.frame = imageView.bounds;
    [imageView addSubview:visualEffectView];

How to integrate inside a TabBarViewController

Trying to add this view as one of my storyboard tabs but have issue with init (no way to call it from storyboard) and when I call from tab code it hides the tab bar.

Any suggestion?

How to use this in Swift 3

Hi,

I am very new to iOS and Swift3, I want use this library and layout in my project. Can you send a sample how to use this in Swift 3.2, I am on all latest technologies.

Main top image

Hi,
MGViewController *spotyViewController = [[MGViewController alloc] initWithMainImage:[UIImage imageNamed:@"example"]];

I not want to use image; In my scenario, i have a tableview cell that i want to add at top; Because i also need some interactions on it. Can it be possible in current state of your control? If not then please suggest things to modify in control.

Thanks,

custom initializer

Hi
it would be better not to use custom initializer for viewController because when sb use seque it just only calls the default initializer method

Crazy performance issues with Swift interop

Your basic blur view setup can use up to 2GB of ram and crash an iPhone 7plus from memory allocations.

Would be cool to see this working with Swift bridging :)

๐Ÿ‘ good job on the objc version

App crashing on memory warnings

I'm downloading pictures from Amazon S3 and setting the main image view via the setMainImage method. This works fine, but when scrolling the app crashes with a memory warning.

Is there a size constraint I should abide by ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.