Skip to content

Instantly share code, notes, and snippets.

View blixt's full-sized avatar
🚧
???

Blixt blixt

🚧
???
View GitHub Profile
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
if (scrollView.contentOffset.x < -scrollView.contentInset.left) {
targetContentOffset->x = -scrollView.contentInset.left;
} else {
*targetContentOffset = CGPointZero;
}
}
- (void)layoutSubviews {
[super layoutSubviews];
// This is necessary to ensure that the content size scales with the view.
self.scrollView.contentSize = self.contentView.bounds.size;
self.scrollView.contentOffset = CGPointZero;
}
2015-01-26 22:19:55.120 SwipeableTableViewCell[21735:2347995] setFrame
frame={{0, 0}, {320, 44}}
self.bounds={{0, 0}, {320, 44}}
self.frame={{0, 0}, {320, 44}}
self.contentView.bounds={{0, 0}, {0, 0}}
self.scrollView.bounds={{0, 0}, {0, 0}}
self.scrollView.frame={{0, 0}, {0, 0}}
self.scrollView.contentOffset={0, 0}
2015-01-26 22:19:55.121 SwipeableTableViewCell[21735:2347995] setFrame
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.x > 0) {
scrollView.contentOffset = CGPointZero;
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.x > 0) {
scrollView.contentOffset = CGPointZero;
}
self.buttonsView.frame = CGRectMake(scrollView.contentOffset.x, 0, 160, self.buttonsView.frame.size.height);
}
@interface AlertViewCallback : NSObject <UIAlertViewDelegate>
@property (copy, nonatomic) void (^callback)(void);
@end
@implementation AlertViewCallback
+ (instancetype)callback:(void (^)(void))callback {
return [[self alloc] initWithCallback:callback];
}
@blixt
blixt / Usage.m
Last active August 29, 2015 14:14
- (void)alertWithTitle:(NSString *)title
message:(NSString *)message
close:(NSString *)closeText
action:(NSString *)actionText
then:(void (^)(void))block
{
if ([UIAlertController class]) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
// Observed bug(?): When adding a button after creating UIAlertView, the firstOtherButtonIndex value
// is stuck as -1 instead of the correct value, 1, even though the documentation states that the two
// invocations below should be equivalent.
NSString *closeText = @"Cancel";
NSString *actionText = @"OK";
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)recognizer {
if (recognizer != self.panGestureRecognizer) {
if ([super respondsToSelector:@selector(gestureRecognizerShouldBegin:)]) {
return [super gestureRecognizerShouldBegin:recognizer];
} else {
return YES;
}
}
CGPoint translation = [recognizer translationInView:self];
@blixt
blixt / workers.go
Last active August 29, 2015 14:17
Stoppable workers with reporting
// Playground: http://play.golang.org/p/G9-_EtwPRg
package main
import (
"fmt"
"math/rand"
"time"
)
type WorkerId int