我正在使用UIView我的应用程序中的子类.当用户触摸视图时,我需要获得该点的坐标; 为此我正在使用:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
currentPoint=[[touches anyObject]locationInView:self];
}
Run Code Online (Sandbox Code Playgroud)
它有一些延迟.任何人都可以给我解决方案立即获得积分吗?谢谢你们.
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
self.frame=frame;
rect=[[NSMutableArray alloc] initWithCapacity:1];
currentPointsList=[[NSMutableArray alloc]initWithCapacity:1];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
firstTouchedPoint = [touch locationInView:self];
NSLog(@"the firstTouched point is %");
for (int i=0; i<[rect count]; i++) {
if(CGRectContainsPoint([[rect objectAtIndex:i]CGRectValue], firstTouchedPoint)){
CGRect firstLineRect = CGRectMake(firstTouchedPoint.x,
[[rect objectAtIndex:i]CGRectValue].origin.y,
[[rect objectAtIndex:i]CGRectValue].size.width-firstTouchedPoint.x+[[rect objectAtIndex:i]CGRectValue].origin.x,
[[rect objectAtIndex:i]CGRectValue].size.height);
UIImageView *firstLine=[[UIImageView alloc]initWithFrame:firstLineRect];
firstLine.backgroundColor=[[UIColor blueColor]colorWithAlphaComponent:0.3f];
[self …Run Code Online (Sandbox Code Playgroud) 我有一组动画需要按顺序操作,每个步骤都要进行各种检查.因为集合的大小是在运行时确定的,所以我希望使用递归调用...但是我无法让它在"块"范例内运行.
无论我是否使用预先声明的块,结果都是EXEC_BAD_ACCESS
__block void (^myBlock)(BOOL) = ^(BOOL finished){ if (finished) [self nextStep];};
Run Code Online (Sandbox Code Playgroud)
或不,如下面的代码片段所示.在调试时,似乎'self'变量确实有效.
NSEnumerator* stepEnumerator;
-(void) mainRoutine {
stepEnumerator = [myArray objectEnumerator];
[self nextStep];
}
-(void) nextStep {
id obj;
if ((obj = [stepEnumerator nextObject])) {
// Do my checking at each location
....
// we have another spot to move to
[UIView animateWithDuration:animationDuration
animations:^{self.frame = newFrame;}
completion:^(BOOL finished){ if (finished) [self nextStep];}];
}
}
else {
// we are done, finish house cleaning
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏.
谢谢!
我很高兴看到这个:如何转换子视图的点的答案 ,它在模拟器上对我来说非常适合.
但由于某种原因,它无法在设备上运行......可能是视图位置由设备管理不同 - 或者它只是另一个谜?或者(希望)我写错了,你们可以帮忙...... :)
这是我的路线:
CGPoint yoel = [imagePressed.imageView convertPoint:imagePressed.frame.origin toView:nil];
Run Code Online (Sandbox Code Playgroud) 我有另一个iOS相关问题.这次与UIView上的addSubView有关.
我在NSMutableArray中存储了一堆UIViewController类.我们的想法是,根据用户从UIPickerView中选择的内容,它会将选择器视图移开,然后显示与视图控制器关联的视图.
为此,我有以下代码:
[navItem setTitle: [cheatArray objectAtIndex:row]];
UIViewController* controller = [cheatViewControllers objectAtIndex: row];
if ( controller != nil )
{
CGPoint animateTo;
animateTo.x = thePickerView.bounds.size.width / 2;
animateTo.y = -thePickerView.bounds.size.height / 2;
[UIView animateWithDuration:0.5f delay: 0.0f options:UIViewAnimationOptionAllowUserInteraction animations:^{ [thePickerView setCenter: animateTo]; } completion:nil];
[self.view addSubView: controller.view];
}
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,当我调用addSubView时,我收到一个错误:
-[UIView addSubView:]: unrecognized selector sent to instance 0x581ba00
Run Code Online (Sandbox Code Playgroud)
我很遗憾这是怎么发生的.addSubView怎么可能是一个无法识别的选择器.肯定是其中一个内置的.有没有人对这里发生的事情有任何想法?
-(void)rotateView:(id)sender {
CGAffineTransform rotateTransform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI);
[sender setTransform:rotateTransform];//the error is shown here
}
Run Code Online (Sandbox Code Playgroud)
我收到此警告错误,并显示名为-setTransform:found的多个方法.它只会在我的头文件中有#import AVFoundation/AVFoundation.h时出现.有什么建议?谢谢
我有一个UIView和一个按钮的视图.按下按钮会弹出一个ModalViewController,它是带有UITextField的UIView.我需要将UIView中的NSObject的字符串值作为字符串传递给ModalViewController.点击按钮我称之为:
-(void) editNote{
TextViewController * vc = [(TextViewController *)[TextViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
[self.navigationController presentModalViewController:nav animated:YES];
[vc release];
}
Run Code Online (Sandbox Code Playgroud)
通常,在行选择时我们使用pushviewcontroller将数据推送到下一个视图,但是在做了很多谷歌后我无法弄清楚如何使用presentmodalviewcontroller传递数据.
我有一个定制的UIView,持有人.
我有另一个来自不同类的自定义UIView,该实例名为letter.
当信件触及持有人时,我希望持有人回复.
我已经在这个视图的底部放置了一些标签,一个按钮,特别是一个文本字段.问题是当文本字段获得焦点时,iphone虚拟键盘会隐藏文本字段,因此我们无法看到我们正在键入的内容(我无法在不破坏此布局的情况下将文本字段移动到另一个部分). ..关于如何解决这个问题的任何想法?
感谢帮助,
斯特凡
我有放置在accelerometer: didAccelerate其中的代码块,用于更改图像的裁剪。基本上,当您倾斜iPad时,图像会被截断(不调整大小),这正是我要的效果。注意:self.xPos受accelerometer.x的位置影响。
UIImage *originalStringImage = [UIImage imageNamed:@"string.png"];
CGImageRef imageRef = CGImageCreateWithImageInRect([originalStringImage CGImage], CGRectMake(0.0f,0.0f, self.xPos+50.0f, 26.0f));
[self.stringImageView setImage:[UIImage imageWithCGImage:imageRef]];
self.stringImageView.frame = CGRectMake(10.0f, self.stringYPos, self.xPos+50.0f, 26.0f);
Run Code Online (Sandbox Code Playgroud)
现在,我想做完全一样的事情,尽管作为UIView动画。这些UIView动画参数之间的区别:
UIImageView *pageStringImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, placeString, 0.0f, 42.0f)];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelay:2.0];
[UIView setAnimationDuration:3.0];
pageStringImageView.frame = CGRectMake(10.0f, placeString, 900.0f, 42.0f);
UIImage *originalStringImage = [UIImage imageNamed:@"string.png"];
CGImageRef imageRef = CGImageCreateWithImageInRect([originalStringImage CGImage], CGRectMake(10.0f,placeString, pageStringImageView.frame.origin.x, 42.0f));
[pageStringImageView setImage:[UIImage imageWithCGImage:imageRef]];
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
但是上述方法并不能解决所有问题。实际上,它甚至不显示图像。我相信这里的主要困难是在运行UIView动画时动态更改图像的大小。
有什么建议或问题吗?
我正在为iPhone创建一个非常简单的应用程序.
只是不知道如何让按钮在触摸时移动到随机位置(但在屏幕上).
我正在使用Xcode 4.2.
uiview ×10
iphone ×6
ios ×5
objective-c ×4
xcode ×3
animation ×2
addsubview ×1
cgpoint ×1
cocoa-touch ×1
enumeration ×1
events ×1
ios4 ×1
touch ×1
transform ×1
uibutton ×1
uitextfield ×1
uitouch ×1