EGOTableViewPullRefresh ios7実装
nanapiのアンサー, Newspicks他いろんなアプリで使われてる引っ張って更新を実装
■ Podfile
pod 'EGOTableViewPullRefresh'
■ storyboardでviewへTableViewをドラッグする。
■ TableViewを選択した状態でビヨーンとViewController.hファイルへ伸ばし、UITableViewのIBOutletをつくる
■ TableViewを選択した状態で右側のOutletsのdelegateからstoryboadのviewの黄色いとこへビヨーンと伸ばす。UITableViewはUIScrollViewを継承しているので、UIScrollViewのdelegateMethodが使える。
■ ViewController.h
#import <UIKit/UIKit.h> #import "EGORefreshTableHeaderView.h" @interface ViewController : UIViewController <EGORefreshTableHeaderDelegate, UITableViewDelegate, UITableViewDataSource>{ EGORefreshTableHeaderView *_refreshHeaderView; // Reloading var should really be your tableviews datasource // Putting it here for demo purposes BOOL _reloading; } @property (weak, nonatomic) IBOutlet UITableView *tableview; @end
■ ViewController.m
- (void)viewDidLoad { [super viewDidLoad]; if (_refreshHeaderView == nil) { EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _tableview.bounds.size.height, self.view.frame.size.width, _tableview.bounds.size.height)]; view.delegate = self; [self.tableview addSubview:view]; _refreshHeaderView = view; } // update the last update date [_refreshHeaderView refreshLastUpdatedDate]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } #pragma mark Data Source Loading / Reloading Methods - (void)reloadTableViewDataSource{ // should be calling your tableviews data source model to reload // put here just for demo _reloading = YES; } - (void)doneLoadingTableViewData{ // model should call this when its done loading _reloading = NO; [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_tableview]; } #pragma mark UIScrollViewDelegate Methods - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView]; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView]; } #pragma mark EGORefreshTableHeaderDelegate Methods - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{ [self reloadTableViewDataSource]; [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0]; } - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{ return _reloading; // should return if data source model is reloading } - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{ return [NSDate date]; // should return date data source was last changed } #pragma mark Memory Management - (void)viewDidUnload { _refreshHeaderView=nil; } - (void)dealloc { _refreshHeaderView = nil; // [super dealloc]; }
■ これでRunするとtableview を下へ引っ張ると動きが確認できる。
Pull down to refresh → Release to refresh → Loading
■ iOS7でめり込みを防ぐやり方はこちら参考
http://lab.4cast.co.jp/?p=1145
■ 文字やクルクルの位置をカスタムしたい時いじるファイル
Pods > EGOTableViewPullRefresh > EGORefreshTableHeaderView.m
UIRefreshControl 背景 実装
TableViewControllerがないTableViewにUIRefreshControlを実装
■ .h
@property (nonatomic, weak) UIRefreshControl *refreshControl;
■ .m
- (void)viewDidLoad { [super viewDidLoad]; //UIRefreshControl 初期化 UIRefreshControl *rc = [[UIRefreshControl alloc] init]; //引っ張ったときのaction追加 [rc addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged]; //tableViewにUIRefreshControl追加 [tableView_ addSubview:rc]; //このままだとクルクルの背景がtableviewより前にくるので、後ろへ [tableView_ sendSubviewToBack:rc]; self.refreshControl = rc; //クルクルの後ろに背景追加 UIImageView *rcImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"refresh_bg.jpg"]]; [self.refreshControl insertSubview:rcImageView atIndex:0]; } - (void)handleRefresh:(id)sender { 処理... //クルクル終了 [self.refreshControl endRefreshing]; }
こんな感じで背景付きでクルクル実装できる。
Macでファイル,ディレクトリのパスをコピー
シェル書いててMacでファイルやディレクトリのパスをコピーする時、右クリックで"情報を見る"から"場所"をコピーする必要があるが、めんどくさい。
iOS WebView viewDidStartLoad 複数呼ばれる
WebViewでviewDidStartLoadでインジケーターを呼びviewDidFinishLoadでインジケーターを消している場合、WebViewの中身によってはviewDidStartLoadが複数呼ばれるので、途切れ途切れになる。IFRAMEやAdsenseなどの広告が原因。
iOS UIScrollVview
ScrollView をstoryboardだけで実装
Android Bitmap シェア実装
AndroidでBitmap画像をシェアする方法
//Bitmap をてきとうに作る Bitmap screenBitmap = getBitmap(viewContainer); // Save this bitmap to a file. File cache = getApplicationContext().getExternalCacheDir(); File sharefile = new File(cache, "toshare.png"); try { FileOutputStream out = new FileOutputStream(sharefile); screenBitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.flush(); out.close(); } catch (IOException e) { } // send it out to share Intent share = new Intent(android.content.Intent.ACTION_SEND); share.setType("image/*"); share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + sharefile)); try { startActivity(Intent.createChooser(share, "Share photo")); } catch (Exception e) { }