Skip to content

Instantly share code, notes, and snippets.

@qfish
Created September 11, 2013 10:09
Show Gist options
  • Save qfish/6521691 to your computer and use it in GitHub Desktop.
Save qfish/6521691 to your computer and use it in GitHub Desktop.
//
// SlideBoard_iPhone.h
//
#import "Bee.h"
#pragma mark -
@interface Slide_iPhone : BeeUIGridCell
{
BeeUIImageView * _photo;
BeeUIZoomView * _zoomView;
}
@end
#pragma mark -
@interface SlideBoard_iPhone : BeeUIBoard <BeeUIScrollViewDataSource>
{
BeeUIButton * _navBackButton;
BeeUIGridCell * _navBackground;
// BeeUILabel * _hoverTitle;
BeeUILabel * _hoverContent;
BeeUIGridCell * _hoverBackground;
BeeUIScrollView * _scroll;
NSObject * _currentSlide;
BOOL _isHoverHidden;
}
@property (nonatomic, retain) NSMutableArray * data;
@end
//
// SlideBoard_iPhone.m
//
#import "SlideBoard_iPhone.h"
#pragma mark -
@implementation Slide_iPhone
+ (CGSize)sizeInBound:(CGSize)bound forData:(NSObject *)data
{
return bound;
}
- (void)load
{
[super load];
CGRect rect = [UIScreen mainScreen].bounds;
_photo = [[BeeUIImageView alloc] initWithFrame:rect];
_photo.indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
_photo.contentMode = UIViewContentModeScaleAspectFill;
_zoomView = [[BeeUIZoomView alloc] initWithFrame:_photo.frame];
_zoomView.backgroundColor = [UIColor blackColor];
[_zoomView setContentSize:_photo.bounds.size];
[_zoomView setContent:_photo animated:NO];
[self addSubview:_zoomView];
}
- (void)unload
{
SAFE_RELEASE_SUBVIEW( _photo );
SAFE_RELEASE_SUBVIEW( _zoomView );
[super unload];
}
- (void)dataDidChanged
{
NSDictionary * data = self.cellData;
if ( data )
{
_photo.url = [data objectForKey:@"image"];
}
}
@end
@implementation SlideBoard_iPhone
@synthesize data = _data;
- (void)load
{
_data = [[NSMutableArray alloc] init];
[_data addObjectsFromArray:@[
@{ @"image": @"http://image.zcool.com.cn/img3/23/11/m_1369734730305.jpg",
@"brief": @"RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code." },
@{ @"image": @"http://image.zcool.com.cn/img3/6/23/m_1369734727051.jpg",
@"brief": @"Ace is an embeddable code editor written in JavaScript. It matches the features and performance of native editors such as Sublime, Vim and TextMate. It can be easily embedded in any web page and JavaScript application. Ace is maintained as the primary editor for Cloud9 IDE and is the successor of the Mozilla Skywriter (Bespin) project."},
@{ @"image": @"http://image.zcool.com.cn/img3/48/55/m_1369734751318.jpg",
@"brief": @"Emmet — the essential toolkit for web-developers. Emmet is a plugin for many popular text editors which greatly improves HTML & CSS workflow:"},
@{ @"image": @"http://image.zcool.com.cn/img3/1/36/m_1369734723619.jpg",
@"brief": @"Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It's the tie to go along with jQuery's tux, and Backbone.js's suspenders."},
@{ @"image": @"http://image.zcool.com.cn/img3/16/20/m_1369734725579.jpg",
@"brief": @"jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript."}
]];
}
- (void)unload
{
[_data removeAllObjects];
[_data release];
_data = nil;
}
- (void)setCurrentEvent
{
NSInteger offset = (int)_scroll.contentOffset.x;
NSInteger index = (int)( (offset + _scroll.frame.size.width - 1) / _scroll.frame.size.width );
NSDictionary * slide = [_data safeObjectAtIndex:index];
CATransition * transition = [CATransition animation];
[transition setDuration:0.3f];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[transition setType:kCATransitionFade];
[self.view.layer addAnimation:transition forKey:nil];
if ( _currentSlide == slide )
{
if ( slide == nil ) {
_hoverBackground.hidden = YES;
}
return;
}
else
{
_currentSlide = slide;
_hoverContent.text = [slide objectForKey:@"brief"];
}
}
- (void)back
{
[self.stack popBoardAnimated:YES];
}
- (void)handleUISignal_BeeUIBoard:(BeeUISignal *)signal
{
[super handleUISignal:signal];
if ( [signal is:BeeUIBoard.CREATE_VIEWS] )
{
[self setTitleString:@"图片"];
[self hideNavigationBarAnimated:NO];
[self showBarButton:self.BARBUTTON_LEFT image:[UIImage imageNamed:@"back_btn_1.png"]];
self.view.backgroundColor = [UIColor blackColor];
_scroll = [[BeeUIScrollView alloc] initWithFrame:CGRectZero];
_scroll.horizontal = YES;
_scroll.pagingEnabled = YES;
_scroll.dataSource = self;
[self.view addSubview:_scroll];
// _navBackground = [[BeeUIGridCell alloc] initWithFrame:CGRectZero];
// _navBackground.backgroundColor = HEX_RGB(0x88000000);
// [self.view addSubview:_navBackground];
_navBackButton = [[BeeUIButton alloc] initWithFrame:CGRectZero];
[_navBackButton setImage:[UIImage imageNamed:@"back_btn_1.png"] forState:UIControlStateNormal];
[_navBackButton setImage:[UIImage imageNamed:@"back_btn_2.png"] forState:UIControlStateHighlighted];
[_navBackButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_navBackButton];
_hoverBackground = [[BeeUIGridCell alloc] initWithFrame:CGRectZero];
_hoverBackground.backgroundColor = HEX_RGB(0x88000000);
[self.view addSubview:_hoverBackground];
// _hoverTitle = [[BeeUILabel alloc] initWithFrame:CGRectZero];
// _hoverTitle.numberOfLines = 0;
// [_hoverBackground addSubview:_hoverTitle];
_hoverContent = [[BeeUILabel alloc] initWithFrame:CGRectZero];
_hoverContent.numberOfLines = 0;
_hoverContent.textAlignment = UITextAlignmentLeft;
_hoverContent.textColor = [UIColor whiteColor];
[_hoverBackground addSubview:_hoverContent];
}
else if ( [signal is:BeeUIBoard.DELETE_VIEWS] )
{
SAFE_RELEASE_SUBVIEW( _scroll );
}
else if ( [signal is:BeeUIBoard.LAYOUT_VIEWS] )
{
_scroll.frame = self.view.frame;
_navBackButton.frame = CGRectMake( 0, 0, 54, 44 );
_navBackground.frame = CGRectMake( 0, 0, self.view.frame.size.width, 44 );
CGRect hoverFrame = CGRectMake( 0, 0, self.view.frame.size.width, 100 );
hoverFrame.origin.y = self.view.frame.size.height - hoverFrame.size.height;
_hoverBackground.frame = hoverFrame;
int padding = 10;
CGRect contentFrame = CGRectMake( padding, padding,
hoverFrame.size.width - padding * 2,
hoverFrame.size.height - padding * 2 );
// _hoverTitle.frame = titleFrame;
_hoverContent.frame = contentFrame;
}
else if ( [signal is:BeeUIBoard.WILL_DISAPPEAR] )
{
}
}
#pragma mark -
- (void)handleUISignal:(BeeUISignal *)signal
{
[super handleUISignal:signal];
if ( [signal is:BeeUIZoomView.SINGLE_TAPPED] )
{
CATransition * transition = [CATransition animation];
[transition setDuration:0.3f];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[transition setType:kCATransitionFade];
[self.view.layer addAnimation:transition forKey:nil];
if ( _isHoverHidden )
{
_navBackground.hidden = YES;
_hoverBackground.hidden = YES;
}
else
{
_navBackground.hidden = NO;
_hoverBackground.hidden = NO;
}
_isHoverHidden = !_isHoverHidden;
}
}
- (void)handleUISignal_BeeUIScrollView:(BeeUISignal *)signal
{
[super handleUISignal:signal];
if ( [signal is:BeeUIScrollView.RELOADED] )
{
[self setCurrentEvent];
}
else if ( [signal is:BeeUIScrollView.DID_STOP] )
{
[self setCurrentEvent];
}
}
#pragma mark -
- (NSInteger)numberOfLinesInScrollView:(BeeUIScrollView *)scrollView
{
return 1;
}
- (NSInteger)numberOfViewsInScrollView:(BeeUIScrollView *)scrollView
{
return _data.count;
}
- (UIView *)scrollView:(BeeUIScrollView *)scrollView viewForIndex:(NSInteger)index scale:(CGFloat)scale
{
Slide_iPhone * cell = [scrollView dequeueWithContentClass:[Slide_iPhone class]];
cell.cellData = [_data safeObjectAtIndex:index];
return cell;
}
- (CGSize)scrollView:(BeeUIScrollView *)scrollView sizeForIndex:(NSInteger)index
{
return [Slide_iPhone sizeInBound:self.view.frame.size
forData:[_data objectAtIndex:index]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment