이제는이 줄을 정확히 따랐으므로 구현 세부 정보, 작동 대답이 부족하며 더 자세히 알고 싶습니다. 특정, 그래서 나는 새로운 질문이 순서에 있다고 생각한다. 분명히 내가 틀렸다면 알려주십시오. 우리는 restart the thread over there을 시도 할 수 있습니다.사용자 정의보기/uiview 하위 클래스에 iphone의 복사/붙여 넣기 컨트롤 구현
기본적으로 사용자가 라벨을 누르고있을 때 UILabel의 텍스트를 대지로 복사하려고합니다. 솔직히, 열심히하지 않습니다. 그러나 시각적 피드백을 제공하는 가장 좋은 방법은 복사 메뉴 옵션이 UIMenuController
인 사용자에게 묻는 것입니다.
iPhone 응용 프로그램 프로그래밍 가이드의 이벤트 처리 섹션, 특히 Copy, Cut, and Paste Operations의 섹션에 따르면 사용자 지정보기에서 복사, 잘라 내기 및 붙여 넣기 작업을 제공 할 수 있어야합니다.
그래서 가이드에 설명 된대로 다음 구현으로 UILabel을 하위 클래스로 분류했지만 UIMenuController가 표시되지 않습니다. 이 사람이 작업을 수행하는 데 필요한 아무것도가 있다는 가이드에는 표시가 없다, 나는 라벨에 누른 때 NSLog 문은 선택이 수행되고 있음을 나타내는 콘솔을 인쇄 않습니다
//
// CopyLabel.m
// HoldEm
//
// Created by Billy Gray on 1/20/10.
// Copyright 2010 Zetetic LLC. All rights reserved.
//
#import "CopyLabel.h"
@implementation CopyLabel
- (void)showCopyMenu {
NSLog(@"I'm tryin' Ringo, I'm tryin' reeeeal hard.");
// bring up editing menu.
UIMenuController *theMenu = [UIMenuController sharedMenuController];
// do i even need to show a selection? There's really no point for my implementation...
// doing it any way to see if it helps the "not showing up" problem...
CGRect selectionRect = [self frame];
[theMenu setTargetRect:selectionRect inView:self];
[theMenu setMenuVisible:YES animated:YES]; // <-- doesn't show up...
}
// obviously, important to provide this, but whether it's here or not doesn't seem
// to change the fact that the UIMenuController view is not showing up
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
BOOL answer = NO;
if (action == @selector(copy:))
answer = YES;
return answer;
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self performSelector:@selector(showCopyMenu) withObject:nil afterDelay:0.8f];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showCopyMenu) object:nil];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showCopyMenu) object:nil];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showCopyMenu) object:nil];
}
@end
을 그래서, 이 일을하기 위해 또 무엇이해야합니까? 그도에 따라 다음이 일을하려고 들어
, 당신은 또한 라벨 '사용 가능 사용자 상호 작용'을 설정해야합니다
편집 : 명확성을 위해
은, 내가 있음을 추가 할 수 있습니다 이것은 특정 아이폰을 볼 때 이미지 위에 나타나는 작은 [Copy] 메뉴 항목과 비슷해야합니다. -B
일단 내가이 작업을하면 Mobile Orchard : http://www.mobileorchard.com/hold-and-copy-in-uikit/ –
자습서가 내가 필요한 것입니다. 하지만 "재설정"메소드 코드를 추가하는 것을 잊어 버렸습니다. 고맙습니다! – AlBeebe