Skip to content

Instantly share code, notes, and snippets.

@yoshimin
yoshimin / gist:3300593
Created August 9, 2012 03:16
UITableViewCellのサブクラスを作り、initで2枚のUIViewをaddsubView
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backCell = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, 80.0)];
UIImageView *cellBackBkgView = [[UIImageView alloc] init];
cellBackBkgView.backgroundColor = [UIColor whiteColor];
sunImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 27.5, 25.0, 25.0)];
@yoshimin
yoshimin / gist:3300762
Created August 9, 2012 03:46
touchesBeganにて、タッチ開始の座標を取得
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
firstTouch = [touch locationInView:self];
}
@yoshimin
yoshimin / gist:3300764
Created August 9, 2012 03:47
指が動かされた時、現在地とタッチ開始地点の距離を測る
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
if (slideEnabled == NO) return;
[self toggleTableScrolling:NO];
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self];
CGRect frame = frontCell_.frame;
@yoshimin
yoshimin / gist:3300772
Created August 9, 2012 03:50
指が離された時点での、移動距離によって処理を書く
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
if (SlideDistance == kDragDistance) {
NSLog(@"太陽さんさ〜ん!");
} else if (SlideDistance == -kDragDistance) {
NSLog(@"三日月おつきさま!");
}
[self springBack];
@yoshimin
yoshimin / gist:3300773
Created August 9, 2012 03:51
ジェスチャーキャンセル時
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event];
[self springBack];
}
@yoshimin
yoshimin / gist:3300775
Created August 9, 2012 03:53
animateWithDuration:delay:options:animations:completion:によってアニメーションを定義
-(void)springBack {
slideEnabled = NO;
CGRect frame = frontCell_.frame;
frame.origin = CGPointMake(0, 0);
[UIView animateWithDuration:0.1
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
frontCell_.frame = frame;
@yoshimin
yoshimin / gist:3300790
Created August 9, 2012 03:54
これを呼び出したいクラスで、UITableViewCellの代わりに、このクラス名(ここではSlidingTableViewCell)を使って定義
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
SlidingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[SlidingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
@yoshimin
yoshimin / gist:3377792
Created August 17, 2012 10:24
セルに張っていたUIViewに、UIPanGestureRecognizerを付ける
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backCell = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, 80.0)];
UIImageView *cellBackBkgView = [[UIImageView alloc] init];
cellBackBkgView.backgroundColor = [UIColor whiteColor];
sunImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 27.5, 25.0, 25.0)];
@yoshimin
yoshimin / gist:3377794
Created August 17, 2012 10:24
セルに張っていたUIViewに、UIPanGestureRecognizerを付ける
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backCell = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, 80.0)];
UIImageView *cellBackBkgView = [[UIImageView alloc] init];
cellBackBkgView.backgroundColor = [UIColor whiteColor];
sunImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 27.5, 25.0, 25.0)];
@yoshimin
yoshimin / gist:3377806
Created August 17, 2012 10:26
UIPanGestureRecognizerで指定した@selector(panGesture:)の処理を書く
- (void)panGesture:(UIPanGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
startPoint = [sender locationInView:frontCell_];
}
if (sender.state == UIGestureRecognizerStateChanged) {
CGPoint nowPoint = [sender locationInView:frontCell_];
if (slideEnabled == NO) return;