TouchDown 잡아와서 터치지점의 CGPoint로 이벤트 핸들링을 할 일이 생겼는데..
UITapGesture에서 TouchUp이벤트를 주는 건 알겠는데
TouchDown을 하려고 보니까 뭔가 귀찮은게 있는 듯.
안드로이드에서는 쉬웠던거 같은데...
UIGesture로 하려고 하면 복잡하듯 해서,
touchesBegan에서 잡아서 하니까 된다...
TouchDown 잡아와서 터치지점의 CGPoint로 이벤트 핸들링을 할 일이 생겼는데..
UITapGesture에서 TouchUp이벤트를 주는 건 알겠는데
TouchDown을 하려고 보니까 뭔가 귀찮은게 있는 듯.
안드로이드에서는 쉬웠던거 같은데...
UIGesture로 하려고 하면 복잡하듯 해서,
touchesBegan에서 잡아서 하니까 된다...
NSIndexPath* ip = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
[tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:YES];
http://stackoverflow.com/questions/2156614/how-to-start-uitableview-on-the-last-cell
어떤 이벤트/처리를 기다릴때,
sleep하면 처리자체가 멈추므로.
현재의 메인스레드 이외에는 멈추면 안됨.
그럴때, while문 사이에..
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
스테이터스바 표시
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
http://stackoverflow.com/questions/12661031/how-to-hide-a-status-bar-in-ios
스테이터스바 텍스트 컬러
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
http://stackoverflow.com/questions/17678881/how-to-change-status-bar-text-color-in-ios-7
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
// Chooses the photo at the last index
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:([group numberOfAssets] - 1)] options:0 usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];
[latestPhoto resizeImageToWidth:50];
if (latestPhoto){
[self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateNormal];
[self.imgBtn setBackgroundImage:latestPhoto forState:UIControlStateHighlighted];
}
}
}];
} failureBlock: ^(NSError *error) {
}];
http://stackoverflow.com/questions/8867496/get-last-image-from-photos-app
카메라 관련의 주의점
AVCaptureDevice observer를 추가할 때
다른 인스턴스라고 하더라도 같이 영향을 받는 듯.
계속 크래시 하길래, 조사했더니
AVCaptureDevice에 NSKeyValueObservingOptionNew를 등록하고는 해제해주지 않은 채로,
새로운 뷰컨트롤러에서 카메라를 쓰려고 할때 같은 옵저버를 등록하려고 하자.
BAD ACCESS에러로 크래쉬.
뷰가 사라지는 지점에서 해제해주자, 현상은 없어졌다.
NSArray *array = [NSArray arrayWithObjects:@"1",@"2",@"3", nil];
NSMutableArray *dataArray = [NSMutableArray arrayWithArray:array];
[dataArray addObject:@"4"];
NSArray *array2 = [NSArray arrayWithObjects:@"5",@"6",@"7", nil];
[dataArray addObjectsFromArray:array2];
for(NSString *str in dataArray){
NSLog(@"%@", str);
}
결과
2013-12-25 14:38:54.899 TestPrj[2030:70b] 1
2013-12-25 14:38:54.901 TestPrj[2030:70b] 2
2013-12-25 14:38:54.901 TestPrj[2030:70b] 3
2013-12-25 14:38:54.902 TestPrj[2030:70b] 4
2013-12-25 14:38:54.902 TestPrj[2030:70b] 5
2013-12-25 14:38:54.902 TestPrj[2030:70b] 6
2013-12-25 14:38:54.903 TestPrj[2030:70b] 7
mport tkinter.messagebox
def hello():
tkinter.messagebox.showinfo('hello','hello')
var = tkinter.messagebox.askyesno('select','')
tkinter.messagebox.showinfo('your select', 'You selected '+str(var))
hello()
*MessageBox
import tkinter.messagebox
tkinter.messagebox.showinfo('','')
* ConfirmBox
import tkinter.messagebox
var = tkinter.messagebox.askquestion('title','question')
//tkinter.messagebox.askyesno('','')
http://stackoverflow.com/questions/1052420/tkinter-message-box
import threading, time
def hello():
i = 0
while i < 5:
i = i + 1
print("hello "+str(i))
time.sleep(1.0)
inp = input("input time? ")
try:
numInp = int(inp)
print("input value : " + inp)
except ValueError:
print("input value is not valid. \n default : 1")
numInp = 1.0
t = threading.Timer(numInp, hello)
t.start()
<<캐스팅>>
* 숫자 -> 문자열
str(10)
*문자열 -> 숫자
int('10')
http://stackoverflow.com/questions/961632/converting-integer-to-string-in-python
문자연산
우리의 영원한 친구
복사 붙붙붙
**한줄
dd : 한줄잘라내기
p : 붙여넣기
yy : 한줄 복사
p
** 여러줄
v -> v : 영역 지정
y : 복사
p
d : 잘라내기
p
참고로 : undo는 u
from os import rename, listdir, sys
files = listdir('.')
if len(sys.argv) is 1:
print("input target string and replace string..")
exit(0)
if len(sys.argv) is 2:
print("input replace string..")
exit(0)
targetStr = sys.argv[1]
replaceStr = sys.argv[2]
for name in files:
# if name.startswith('b'):
if name.startswith(targetStr):
newname = name.replace(targetStr,replaceStr)
rename(name,newname)
print(name + ' -> ' + newname)
파일이름 일괄변경
http://www.appilogue.kr/2844289
파라메터
http://mwultong.blogspot.com/2007/01/python-sysargv-command-line-argument.html
먼저 파이썬 버전을 정한다.
2.x버전은 OSX에 이미 깔려있다.
-> 터미널에서 Python -V로 확인
3.x버전을 사용하려면, 새로 다운로드받아서 깔아야한다.
http://www.python.org/download/
두버전간의 문법도 틀림.
2.x를 유지하는 이유는 3.x버전에서는 하위호환성이 없기 때문이란다.
helloworld.py
#!/usr/bin/python
#print "hello world" <- ver2 style <- Pythone의 주석문은 #
print("hello world") <- ver3
python3 helloworld.py
- (NSString *) platform
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
...
});
프레임워크를 추가했는데
추가한 프레임워크가 아닌 다른곳에서 계속 에러가 난다.
프로젝트의 복사본으로 여러차례 테스트해본결과,
프로젝트안의 프로젝트에서 프레임워크로 쓰는 xxx.a파일이 생성되어있지 않은것을 확인.
컴파일로 xxx.a파일을 생성해서 link binary framework의 빨간색을 다 없애자 문제가 해결됨.
-> 해결안됨.
프로젝트 파일의 변경을 조사한 결과
FRAMEWORK_SEARCH_PATHS에서
- "\"$(SRCROOT)/FacebookSDK\"",
+ "\\\\\\\"$(SRCROOT)/FacebookSDK\\\\\\\"",
가 되어있는 것을 발견.
원래대로 돌려주니까,빌드 성공.
xcode의 버그인듯?
- (void)webViewDidFinishLoad:(UIWebView *)webView{
// 링크 길게 누르면 나오는 메뉴를 안나오게
[self.webview stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];
// 길게 눌러서 선택 안되게
[self.webview stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
}
xcode5, iOS5
iOS5에서만 정상적으로 작동해서,
움직임을 확인하려고, 프로젝트를 만들려고 했더니,
빌드타겟을 iOS5로 하고 실행시키면,
스토리보드 못찾겠다고 에러가 난다.
일단, 실행되게 하려면,
http://need-bee.com/b/2013/08/could-not-find-a-storyboard-in-xcode-5-for-ios-5-0/
근데, 실행은 되는데 스토리보드에 있는 콤포넌트들을 못읽어오네?..
그냥 코드로 만들어 붙여서 테스트 했다.
요롷고롬 하면 됨.
CGRect rect = /* FULL SCREEN */;
[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:rect];
→
[self.tabBarController.tabBar setHidden:YES];
[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:self.tabBarController.view.frame];
http://stackoverflow.com/questions/2426248/uitabbar-leaves-a-white-rectangle-when-hidden
// 디폴트 링크 전부 삭제
[self.ohlabel setAutomaticallyAddLinksForType:0];
//링크만 체크 (숫자로 전화걸리는 링크는 삭제하고 싶을때)
[self.ohlabel setAutomaticallyAddLinksForType:NSTextCheckingTypeLink];
참고링크
**문자열로부터 URL, 전화번호를 취득.
http://www.sirochro.com/note/objc-nsdatadetector-using/
** 링크 기능 죽이기
https://github.com/AliSoftware/OHAttributedLabel/issues/112
** Global Queue
dispatch_queue_t syncQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(syncQueue, ^{
});
** Main Queue
dispatch_async(dispatch_get_main_queue(), ^{
});
** private Queue
dispatch_queue_t queue; |
queue = dispatch_queue_create("com.example.MyQueue", NULL); |
************
Simple block sample
int x = 123; |
int y = 456; |
// Block declaration and assignment |
void (^aBlock)(int) = ^(int z) { |
printf("%d %d %d\n", x, y, z); |
}; |
// Execute the block |
aBlock(789); // prints: 123 456 789 |
************
...Block:(void(^)(int b, intc))block{
block(1, 2);
}
#import "Reachability.h"
+ (BOOL)isConnectedToInternet
{
Reachability *reachability = [Reachability reachabilityForInternetConnection];
return NotReachable != [reachability currentReachabilityStatus];
}
bundler identifier에 이상한 문자가 들어가면
AFURLConnectionOperation에서 Bad Access로 기동이 안되고,
어플이 강제종료 되는 현상이 있다.
XCode5
iOS5, iOS6에서 현상 있음.
iOS7에서는 문제없음.
https://www.google.com/android/devicemanager
계정에 등록되어 있는 기기의 위치를 알수 있다.
벨소리도 울린다!