iPhone SDKhttp://kishikawakatsumi.comTwitter@k_katsumi24/7 twenty-four sevenhttp://d.hatena.ne.jp/KishikawaKatsumi/
iPhone SDKhttp://kishikawakatsumi.comTwitter@k_katsumi24/7 twenty-four sevenhttp://d.hatena.ne.jp/KishikawaKatsumi/
iPhone SDK•     touch   •      on the WEB•LDR touch    ••             •i-Radio•LCD Clock    ••Subway Map   ••MyWebClip•   ...
iPhone SDKhttp://github.com/kishikawakatsumi•hatena-touch     •DescriptionBuilder•ldr-touch        •TiledLayerView•tv-list...
iPhone SDKhttp://github.com/kishikawakatsumi•UICKeyChainStore•TiKeyChainStore•CropImageSample
iPhone SDK
iPhone SDK
iPhone SDK
iPhone SDK
iPhone SDK
iPhone SDK#import <UIKit/UIKit.h>extern NSString * const FFNavigationBarSwipedNotification;@interface FFNavigationBar : UI...
#import "FFNavigationBar.h"@implementation FFNavigationBar          iPhone SDK- (void)initCommon {    self.barStyle = UIBa...
- (id)initWithCoder:(NSCoder *)coder {    self = [super initWithCoder:coder];        iPhone SDK    if (self) {        [sel...
iPhone SDK
iPhone SDKUITableView
iPhone SDKUITableViewCell
iPhone SDK
iPhone SDKiPhone
iPhone SDK
iPhone SDK
iPhone SDK•UIImageView•CALayer•[UIImage drawRect:]
iPhone SDK•UIImageView•CALayer•[UIImage drawRect:]
iPhone SDKUIImageViewUIImageViewCALayerUIImage   draw~                  UIButton
iPhone SDKUIImage   draw~PNGhttp://sonson.jp/?p=745                  PNG=>        UI=>=>JPEG
iPhone SDKCALayer *backgroundImageLayer = [CALayer layer];backgroundImageLayer.frame =CGRectMake(17.0f, 12.0f, 285.0f, 310...
iPhone SDKpreloaderBackground =[[UIImageView alloc]initWithFrame:CGRectMake(95.0f, 95.0f, 70.0f, 70.0f)];preloaderBackgrou...
iPhone SDKCALayer *shadowLayer = [CALayer layer];shadowLayer.frame =CGRectMake(30.0f, 18.0f, 260.0f, 260.0f);shadowLayer.c...
iPhone SDK
iPhone SDK     NSCache        NSDictionary
@interface FFImageCache : NSObject {    NSFileManager *fileManager;           iPhone SDK    NSString *cacheDirectory;    N...
iPhone SDK=>
- (UIImage *)cachedImageWithURL:(NSString *)URL                   defaultImage:(UIImage *)defaultImage {           iPhone ...
+ (NSString *)keyForURL:(NSString *)URL {! if ([URL length] == 0) {! !! }      iPhone SDK       return nil;! const char *c...
iPhone SDK
iPhone SDK
- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView {         iPhone SDK    if (!scrollView.isDecelerating) {   ...
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {    [self loadImagesForOnscreenRows];          iPhone SDK...
CGFloat delta;    NSIndexPath *indexPath;    if (scrollDirection == ScrollDirectionUp) {              iPhone SDK        in...
iPhone SDK
iPhone SDK
iPhone SDK
- (void)animateIcon:(BOOL)flag {    [UIView transitionFromView:flag ? icon : selectedIcon          iPhone SDK             ...
- (void)setSelected:(BOOL)selected {    [super setSelected:selected];    if (selected) {              iPhone SDK        ic...
iPhone SDK
iPhone SDKUITableView
photoScrollView = [[UITableView alloc] initWithFrame:CGRectMake(6.0f,30.0f, 50.0f, 264.0f)];           iPhone SDKphotoScro...
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {    return 1;          iPhone SDK}- (NSInteger)tableVie...
- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {          iPhone SD...
- (void)scrollViewDidScroll:(UIScrollView *)sender {    if (pageControlUsed) {          iPhone SDK        return;    }    ...
iPhone SDK
CGFloat x = 41.0f;CGSize size;              iPhone SDKNSString *username = user.username;if ([username length] > 0) {    U...
iPhone SDK
Upcoming SlideShare
Loading in …5
×

I phone勉強会 (2011.11.23)

7,066 views
7,037 views

Published on

UI & performance tips.

Published in: Technology, News & Politics
1 Comment
14 Likes
Statistics
Notes
No Downloads
Views
Total views
7,066
On SlideShare
0
From Embeds
0
Number of Embeds
3,401
Actions
Shares
0
Downloads
58
Comments
1
Likes
14
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • I phone勉強会 (2011.11.23)

    1. 1. iPhone SDKhttp://kishikawakatsumi.comTwitter@k_katsumi24/7 twenty-four sevenhttp://d.hatena.ne.jp/KishikawaKatsumi/
    2. 2. iPhone SDKhttp://kishikawakatsumi.comTwitter@k_katsumi24/7 twenty-four sevenhttp://d.hatena.ne.jp/KishikawaKatsumi/
    3. 3. iPhone SDK• touch • on the WEB•LDR touch •• •i-Radio•LCD Clock ••Subway Map ••MyWebClip• •
    4. 4. iPhone SDKhttp://github.com/kishikawakatsumi•hatena-touch •DescriptionBuilder•ldr-touch •TiledLayerView•tv-listings •UICCalendarPicker•MapKit-Route-Directions•FlipCardNavigationView•PhotoFlipCardView
    5. 5. iPhone SDKhttp://github.com/kishikawakatsumi•UICKeyChainStore•TiKeyChainStore•CropImageSample
    6. 6. iPhone SDK
    7. 7. iPhone SDK
    8. 8. iPhone SDK
    9. 9. iPhone SDK
    10. 10. iPhone SDK
    11. 11. iPhone SDK#import <UIKit/UIKit.h>extern NSString * const FFNavigationBarSwipedNotification;@interface FFNavigationBar : UINavigationBar@end
    12. 12. #import "FFNavigationBar.h"@implementation FFNavigationBar iPhone SDK- (void)initCommon { self.barStyle = UIBarStyleBlack;}- (id)init { self = [super init]; if (self) { [self initCommon]; } return self;}- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initCommon]; } return self;}
    13. 13. - (id)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; iPhone SDK if (self) { [self initCommon]; } return self;}- (void)drawRect:(CGRect)rect { [background drawAsPatternInRect:rect];}@end
    14. 14. iPhone SDK
    15. 15. iPhone SDKUITableView
    16. 16. iPhone SDKUITableViewCell
    17. 17. iPhone SDK
    18. 18. iPhone SDKiPhone
    19. 19. iPhone SDK
    20. 20. iPhone SDK
    21. 21. iPhone SDK•UIImageView•CALayer•[UIImage drawRect:]
    22. 22. iPhone SDK•UIImageView•CALayer•[UIImage drawRect:]
    23. 23. iPhone SDKUIImageViewUIImageViewCALayerUIImage draw~ UIButton
    24. 24. iPhone SDKUIImage draw~PNGhttp://sonson.jp/?p=745 PNG=> UI=>=>JPEG
    25. 25. iPhone SDKCALayer *backgroundImageLayer = [CALayer layer];backgroundImageLayer.frame =CGRectMake(17.0f, 12.0f, 285.0f, 310.0f);backgroundImageLayer.contents = (id)[[UIImageimageNamed:@"photo_bg.png"] CGImage];[self.contentView.layer addSublayer:backgroundImageLayer];photoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30.0f, 18.0f, 260.0f, 260.0f)];photoImageView.backgroundColor = [UIColor clearColor];[self.contentView addSubview:photoImageView];[photoImageView release];
    26. 26. iPhone SDKpreloaderBackground =[[UIImageView alloc]initWithFrame:CGRectMake(95.0f, 95.0f, 70.0f, 70.0f)];preloaderBackground.backgroundColor = [UIColorclearColor];preloaderBackground.image = [UIImageimageNamed:@"photo_preloader.png"];[photoImageView addSubview:preloaderBackground];[preloaderBackground release];preloader =[[FFPreloaderView alloc]initWithFrame:CGRectMake(5.0f, 1.0f, 60.0f, 20.0f)];[preloaderBackground addSubview:preloader];[preloader release];
    27. 27. iPhone SDKCALayer *shadowLayer = [CALayer layer];shadowLayer.frame =CGRectMake(30.0f, 18.0f, 260.0f, 260.0f);shadowLayer.contents = (id)[[UIImageimageNamed:@"photo_shadow.png"] CGImage];[cellContentView.layer addSublayer:shadowLayer];favoriteButton = [[FFFavoriteButton alloc]initWithFrame:CGRectMake(19.0f, 24.0f, 75.0f, 29.0f)];favoriteButton.exclusiveTouch = YES;
    28. 28. iPhone SDK
    29. 29. iPhone SDK NSCache NSDictionary
    30. 30. @interface FFImageCache : NSObject { NSFileManager *fileManager; iPhone SDK NSString *cacheDirectory; NSCache *cache;}+ (FFImageCache *)sharedInstance;- (UIImage *)cachedImageWithURL:(NSString *)URL;- (UIImage *)cachedImageWithURL:(NSString *)URL defaultImage:(UIImage *)defaultImage;- (UIImage *)cachedImageWithURL:(NSString *)URL size:(NSInteger)size;- (UIImage *)cachedImageWithURL:(NSString *)URL size:(NSInteger)size defaultImage:(UIImage *)defaultImage;- (void)storeImage:(UIImage *)image data:(NSData *)data URL:(NSString *)URL;- (void)purgeMemoryCache;- (void)deleteAllCacheFiles;@end
    31. 31. iPhone SDK=>
    32. 32. - (UIImage *)cachedImageWithURL:(NSString *)URL defaultImage:(UIImage *)defaultImage { iPhone SDK NSString *key = [FFImageCache keyForURL:URL]; UIImage *cachedImage = [cache objectForKey:key]; if (cachedImage) { return cachedImage; } cachedImage = [UIImage imageWithContentsOfFile:[self pathForKey:key]]; if (cachedImage) { [cache setObject:cachedImage forKey:key]; } return cachedImage;}- (void)storeImage:(UIImage *)image data:(NSData *)data URL:(NSString *)URL{ NSString *key = [FFImageCache keyForURL:URL]; [cache setObject:image forKey:key]; [data writeToFile:[self pathForKey:key] atomically:NO];}
    33. 33. + (NSString *)keyForURL:(NSString *)URL {! if ([URL length] == 0) {! !! } iPhone SDK return nil;! const char *cStr = [URL UTF8String];! unsigned char result[16];! CC_MD5(cStr, (CC_LONG)strlen(cStr), result);! return [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", result[0], result[1], result[2], result[3],result[4], result[5], result[6], result[7],result[8],result[9], result[10], result[11],result[12], result[13],result[14], result[15]]; !}
    34. 34. iPhone SDK
    35. 35. iPhone SDK
    36. 36. - (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView { iPhone SDK if (!scrollView.isDecelerating) { contentOffsetY = scrollView.contentOffset.y; }}- (void)scrollViewDidEndDragging:(UIScrollView *)scrollViewwillDecelerate:(BOOL)decelerate { shouldSnapScroll = scrollView.isTracking && scrollView.isDragging && ! scrollView.isDecelerating; if (!decelerate) { [self loadImagesForOnscreenRows]; }}
    37. 37. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { [self loadImagesForOnscreenRows]; iPhone SDK CGFloat distance = ABS(distance = contentOffsetY - scrollView.contentOffset.y); if (distance > timelineView.frame.size.height * 2) { shouldSnapScroll = YES; } if (!shouldSnapScroll) { return; } NSArray *indexPaths = timelineView.indexPathsForVisibleRows; if ([indexPaths count] == 0) { return; } if (contentOffsetY > scrollView.contentOffset.y) { scrollDirection = ScrollDirectionUp; } else { scrollDirection = ScrollDirectionDown; }
    38. 38. CGFloat delta; NSIndexPath *indexPath; if (scrollDirection == ScrollDirectionUp) { iPhone SDK indexPath = [indexPaths objectAtIndex:0]; CGRect rect = [timelineView rectForSection:indexPath.section]; delta = scrollView.contentOffset.y - rect.origin.y; if (delta > 250.0f) { indexPath = [indexPaths lastObject]; rect = [timelineView rectForSection:indexPath.section]; delta = rect.origin.y - scrollView.contentOffset.y; if (delta < 0.0f) { return; } } } else { indexPath = [indexPaths lastObject]; CGRect rect = [timelineView rectForSection:indexPath.section]; delta = rect.origin.y - scrollView.contentOffset.y; if (indexPath.section == [timelineManager count] - 1) { return; } if (delta < 0.0f) { return; } if (delta > 200.0f) { indexPath = [indexPaths objectAtIndex:0]; } } if (scrollView.contentInset.top < 60.0f && scrollView.contentOffset.y > 0.0f) { NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:0inSection:indexPath.section]; [timelineView scrollToRowAtIndexPath:toIndexPathatScrollPosition:UITableViewScrollPositionTop animated:YES]; }}
    39. 39. iPhone SDK
    40. 40. iPhone SDK
    41. 41. iPhone SDK
    42. 42. - (void)animateIcon:(BOOL)flag { [UIView transitionFromView:flag ? icon : selectedIcon iPhone SDK toView:flag ? selectedIcon : icon duration:0.4options:UIViewAnimationOptionTransitionFlipFromRight |UIViewAnimationOptionShowHideTransitionViews completion: ^(BOOL finished) { if (!animaitionFinished) { [self animateIcon:!flag]; } }];}- (void)setEnabled:(BOOL)enabled { [super setEnabled:enabled]; if (enabled) { animaitionFinished = YES; } else { animaitionFinished = NO; shouldStartZoomAnimation = YES; [self animateIcon:self.selected]; }}
    43. 43. - (void)setSelected:(BOOL)selected { [super setSelected:selected]; if (selected) { iPhone SDK icon.hidden = YES; selectedIcon.hidden = NO; animationIcon.image = [UIImage imageNamed:@"button_favorite_icon_selected.png"]; } else { icon.hidden = NO; selectedIcon.hidden = YES; animationIcon.image = [UIImage imageNamed:@"button_favorite_icon.png"]; } if (shouldStartZoomAnimation) { shouldStartZoomAnimation = NO; CABasicAnimation *zoom = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; zoom.toValue = [NSNumber numberWithFloat:8.0f]; CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"opacity"]; fade.toValue = [NSNumber numberWithFloat:0.0f]; CAAnimationGroup *group = [CAAnimationGroup animation]; group.delegate = self; group.animations = [NSArray arrayWithObjects:zoom, fade, nil]; group.duration = 0.5; animationIcon.hidden = NO; [animationIcon.layer addAnimation:group forKey:nil]; }}- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { animationIcon.hidden = YES;}
    44. 44. iPhone SDK
    45. 45. iPhone SDKUITableView
    46. 46. photoScrollView = [[UITableView alloc] initWithFrame:CGRectMake(6.0f,30.0f, 50.0f, 264.0f)]; iPhone SDKphotoScrollView.delegate = self;photoScrollView.dataSource = self;photoScrollView.rowHeight = 44.0f;photoScrollView.separatorColor = [UIColor clearColor];photoScrollView.pagingEnabled = YES;photoScrollView.showsHorizontalScrollIndicator = NO;photoScrollView.showsVerticalScrollIndicator = NO;photoScrollView.backgroundColor = [UIColor clearColor];photoScrollView.transform = CGAffineTransformMakeRotation(M_PI / -2.0f);photoScrollView.center = CGPointMake(146.0f, 56.0f);[cellContentView addSubview:photoScrollView];[photoScrollView release];pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(12.0f, 72.0f,264.0f, 36.0f)];pageControl.clipsToBounds = YES;pageControl.hidesForSinglePage = YES;pageControl.userInteractionEnabled = NO;[cellContentView addSubview:pageControl];[pageControl release];UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(scrollViewTapped:)];[photoScrollView addGestureRecognizer:tapRecognizer];[tapRecognizer release];
    47. 47. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; iPhone SDK}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSUInteger count = [photos count]; if (count == 0) { pageControl.numberOfPages = 0; } else { pageControl.numberOfPages = MIN(count / 6 + 1, 17) ; } pageControl.currentPage = 0; return count;}
    48. 48. - (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath { iPhone SDK NSUInteger count = [photos count]; NSUInteger numPages = count / 6 + 1; photoScrollView.contentSize = CGSizeMake(50.0f, 264.0f *numPages); static NSString *cellIdentifier = @"Cell"; FFMyPhotoImageCell *cell = (FFMyPhotoImageCell *)[tableViewdequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[[FFMyPhotoImageCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier]autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } cell.URL = [[photos objectAtIndex:indexPath.row]objectForKey:FFURLKey]; return cell;}
    49. 49. - (void)scrollViewDidScroll:(UIScrollView *)sender { if (pageControlUsed) { iPhone SDK return; } CGFloat pageWidth = photoScrollView.bounds.size.height; int page = floor((photoScrollView.contentOffset.y -pageWidth / 2) / pageWidth) + 1;! currentPage = MIN(page, 16);}- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { pageControlUsed = NO; pageControl.currentPage = currentPage;}- (void)scrollViewTapped:(UIGestureRecognizer *)gestureRecognizer{ UITableView *tableView = (UITableView *)self.superview; [tableView.delegate tableView:tableViewdidSelectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];}
    50. 50. iPhone SDK
    51. 51. CGFloat x = 41.0f;CGSize size; iPhone SDKNSString *username = user.username;if ([username length] > 0) { UIFont *commentUsernameFont = [FFConstants commentUsernameFont]; size = [username sizeWithFont:commentUsernameFont forWidth:253.0f - xlineBreakMode:UILineBreakModeTailTruncation]; [username drawInRect:CGRectMake(x, 6.0f, size.width, 12.0f) withFont:commentUsernameFontlineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft]; x += size.width; NSString *action = NSLocalizedString(@" faved.", nil); UIFont *commentFont = [FFConstants commentFont]; size = [action sizeWithFont:commentFont forWidth:253.0f - xlineBreakMode:UILineBreakModeClip]; [action drawInRect:CGRectMake(x, 6.0f, size.width, 12.0f) withFont:commentFontlineBreakMode:UILineBreakModeClip alignment:UITextAlignmentLeft]; NSMutableString *str = [NSMutableString string]; NSUInteger index = 0; NSUInteger length = [action length];; for (; index < length; index++) { [str appendString:[action substringWithRange:NSMakeRange(index, 1)]]; CGSize sz = [str sizeWithFont:commentFont forWidth:253.0f - xlineBreakMode:UILineBreakModeClip]; if (sz.width >= size.width) { index++; break; } } action = [action substringWithRange:NSMakeRange(index, length - index)]; [action drawInRect:CGRectMake(41.0f, 22.0f, 212.0f, 12.0f) withFont:commentFontlineBreakMode:UILineBreakModeClip alignment:UITextAlignmentLeft];}
    52. 52. iPhone SDK

    ×