我正在尝试将手势识别器附加到我自己的类,这是UILabel的子类,但它不起作用.你能帮我理解代码中的错误吗?
@interface Card : UILabel {
}
- (void) addBackSideWord;
@end
#import "Card.h"
@implementation Card
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(addBackSideWord)];
[tapRecognizer setNumberOfTouchesRequired:2];
[tapRecognizer setDelegate:self];
[self addGestureRecognizer:tapRecognizer];
}
return self;
}
- (void) addBackSideWord {
//do something
}
@end
Run Code Online (Sandbox Code Playgroud) 这是一张简单的图纸
- (void)drawRect:(CGRect)rect
{
//vertical line with 1 px stroking
UIBezierPath *vertLine = [[UIBezierPath alloc] init];
[vertLine moveToPoint:CGPointMake(20.0, 10.0)];
[vertLine addLineToPoint:CGPointMake(20.0, 400.0)];
vertLine.lineWidth = 1.0;
[[UIColor blackColor] setStroke];
[vertLine stroke];
//vertical rectangle 1px width
UIBezierPath *vertRect= [UIBezierPath bezierPathWithRect:CGRectMake(40.0, 10.0, 1.0, 390.0)];
[[UIColor blackColor] setFill];
[vertRect fill];
}
Run Code Online (Sandbox Code Playgroud)
在非视网膜3GS和模拟器上,第一行是模糊的,看起来比1 px宽,但第二行是清晰的.
不幸的是我没有iPhone4和新iPad进行测试,但在视网膜模拟器上两条线看起来都一样.
问题:矩形而非中风是获得非视网膜和视网膜设备相同结果的唯一方法吗?
简化:名为cards的表中有3列.
id packTitle term
id是一列 - 从0到100的整数
packTitle - 描述包的字符串,假设有3种包PACK1,PACK2,PACK3
术语 - 101个项目的不同未分类名称.
通过SQL语句
select packTitle from cards group by packTitle;
Run Code Online (Sandbox Code Playgroud)
我可以获得3个项目的清单.
你能否建议NSPredicate相当于SQL语句GROUP BY.我需要在UITableView中填充一个数组.
我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect rectFake = CGRectZero;
UITextField *fakeField = [[UITextField alloc] initWithFrame:rectFake];
[self.view addSubview:fakeField];
UIView *av = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 39.0)];
av.backgroundColor = [UIColor darkGrayColor];
CGRect rect = CGRectMake(200.0, 4.0, 400.0, 31.0);
UITextField *textField = [[UITextField alloc] initWithFrame:rect];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:24.0];
textField.delegate = self;
[av addSubview:textField];
fakeField.inputAccessoryView = av;
[fakeField becomeFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)
我试着补充一下
[textField becomeFirstResponder]
Run Code Online (Sandbox Code Playgroud)
最后,但它没有用.
在按下ENTER时委托方法隐藏键盘的另一个问题也不起作用.
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
Run Code Online (Sandbox Code Playgroud) UITextView是模态控制器视图的子视图.我需要在键盘出现时降低UITextView高度,以使UITextView的底部边框y坐标等于键盘的顶部y坐标.我想要键盘高度
CGRect frameBegin = [[notification.userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue] ;
CGRect frameEnd = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect resultBegin = [self.view convertRect:frameBegin fromView:nil];
CGRect resultEnd = [self.view convertRect:frameEnd fromView:nil];
CGFloat kbdHeight = resultBegin.origin.y - resultEnd.origin.y;
Run Code Online (Sandbox Code Playgroud)
问题是当键盘出现时,此模态视图会跳起来.在这种情况下如何计算键盘的顶部边框坐标?
现在我正在尝试以下它,它的工作原理.
- (void)findDictionaryWithValueForKey:(NSString *)name {
for (NSDictionary * set in myArray) {
if ([[set objectForKey:@"title"] isEqualToString:name])
\\do something
}
}
Run Code Online (Sandbox Code Playgroud)
编辑: 我在bshirley的帖子中添加了一个额外的参数.现在它看起来更灵活.
- (NSDictionary *)findDictionaryWithValue:(NSString*)name forKey:(NSString *)key {
__block BOOL found = NO;
__block NSDictionary *dict = nil;
[self.cardSetsArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
dict = (NSDictionary *)obj;
NSString *title = [dict valueForKey:key];
if ([title isEqualToString:name]) {
found = YES;
*stop = YES;
}
}];
if (found) {
return dict;
} else {
return nil;
} …Run Code Online (Sandbox Code Playgroud) 这个简单的问题困扰着我.吸气剂是否相同
@property (nonatomic, retain) NSString *name
@property (nonatomic, copy) NSString *name
- (NSString*) name{
return name;
}
Run Code Online (Sandbox Code Playgroud) ios ×7
objective-c ×4
ipad ×2
iphone ×2
xcode ×2
core-data ×1
drawing ×1
ios4 ×1
keyboard ×1
memory ×1
nspredicate ×1
uibezierpath ×1
uitextfield ×1