我正在尝试根据用户的触摸移动 UIView。
这是我目前拥有的:
int oldX, oldY;
BOOL dragging;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(window.frame, touchLocation)) {
dragging = YES;
oldX = touchLocation.x;
oldY = touchLocation.y;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(window.frame, touchLocation) && dragging) {
CGRect frame;
frame.origin.x = (window.frame.origin.x + touchLocation.x - oldX);
frame.origin.y = (window.frame.origin.y + touchLocation.y - oldY);
window.frame = frame;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
dragging = NO;
}
View 一直从一个位置闪烁到另一个位置,我不知道还能做什么。
感谢任何帮助。
最佳答案
您想要的是使用 iOS 3.2 中引入的 UIPanGestureRecognizer。您可以像这样简单地使用它(来自您的 UIViewController 子类):
-(void)viewDidLoad;
{
[super viewDidLoad];
UIPanGestureRecognizer* pgr = [[UIPanGestureRecognizer alloc]
initWithTarget:self
action:@selector(handlePan:)];
[self.panningView addGestureRecognizer:pgr];
[pgr release];
}
-(void)handlePan:(UIPanGestureRecognizer*)pgr;
{
if (pgr.state == UIGestureRecognizerStateChanged) {
CGPoint center = pgr.view.center;
CGPoint translation = [pgr translationInView:pgr.view];
center = CGPointMake(center.x + translation.x,
center.y + translation.y);
pgr.view.center = center;
[pgr setTranslation:CGPointZero inView:pgr.view];
}
}
关于iphone - 移动与触摸有关的 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4488823/
我的代码目前看起来像这样numbers=[1,2,3,4,5]defpop_threepop=[]3.times{pop有没有办法在一行中完成pop_three方法中的内容?我基本上想做类似numbers.slice(0,3)的事情,但要删除切片中的数组项。嗯...嗯,我想我刚刚意识到我可以试试slice! 最佳答案 是numbers.pop(3)或者numbers.shift(3)如果你想要另一边。 关于ruby-多次弹出/移动ruby数组,我们在StackOverflow上找到一
当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?
我从Ubuntu服务器上的RVM转移到rbenv。当我使用RVM时,使用bundle没有问题。转移到rbenv后,我在Jenkins的执行shell中收到“找不到命令”错误。我内爆并删除了RVM,并从~/.bashrc'中删除了所有与RVM相关的行。使用后我仍然收到此错误:rvmimploderm~/.rvm-rfrm~/.rvmrcgeminstallbundlerecho'exportPATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrcecho'eval"$(rbenvinit-)"'>>~/.bashrc.~/.bashrcrbenvversions
我正在尝试使用Ruby中的SeleniumWebDriver2.4模拟鼠标移动如果我运行测试,是否应该看到鼠标在我的屏幕上移动?我很困惑。我试过很多不同的方法示例代码:require'selenium-webdriver'driver=Selenium::WebDriver.for:firefoxdriver.navigate.to'http://www.google.com'element=driver.find_element(:id,'gbqfba')那我试过了driver.action.move_to(element).performdriver.mouse.move_to(e
在控制台中,您可以像这样打印"\b"来删除光标左侧的字符(退格键)print"thelastcharisgoingtobeerased\b"#thelastcharisgoingtobeerased如何只向左移动一个位置而不是删除(向左箭头)? 最佳答案 这取决于终端类型和连接,但通常可以假定ANSI光标移动,因此光标向左是ESC+'['+'D':print"Thecursorshouldbebetweenthearrows:->参见http://ascii-table.com/ansi-escape-sequences.php获取
x={:name=>"John",:data=>{:physical=>{:age=>25,:weight=>150}}}我希望将数据的子属性向上移动一个级别(但不一定只是简单地展平所有属性)。在这种情况下,我基本上想将:physical属性“向上”移动一个级别。我正在尝试这个y=x[:data']y.each{|key|x[key]=y[key]}但是我得到...x=x.except(:data)=>{:name=>"John",[:physical,{:age=>25,:weight=>150}]=>nil}我在找...=>{:name=>"John",:physical=>{:a
我正在为我的网站使用MiddlemanBloggem,但默认情况下,博客文章似乎需要位于/source中,这在查看vim中的树时并不是特别好并尝试在其中找到其他文件之一(例如模板)。通过查看文档,我看不出是否有任何方法可以移动博客文章,以便将它们存储在其他地方,例如blog_articles文件夹或类似文件夹。这可能吗? 最佳答案 将以下内容放入您的config.rb文件中。activate:blogdo|blog|blog.permalink=":year-:month-:day-:title.html"blog.sources=
我的一个模型中有以下方法来保存用户记录:defsave_user(params)beginsave_user_details(params)rescueActiveRecord::RecordInvalid=>ex{success:false,errors:ex.messages}rescueException=>exRails.logger.info(ex.message)Rails.logger.info(ex.backtrace.join(‘\n’){success:false,errors:’Someerroroccurred.}endend我们可以看到rescueblock很
我正在构建一个与RubyonRails后端对话的iPhone应用程序。RubyonRails应用程序还将为Web用户提供服务。restful_authentication插件是提供快速和可定制的用户身份验证的绝佳方式。但是,我希望iPhone应用程序的用户在新列中存储一个由手机的唯一标识符([[UIDevicedevice]uniqueIdentifier])自动创建的帐户。稍后,当用户准备好创建用户名/密码时,帐户将更新为包含用户名和密码,iPhone唯一标识符保持不变。用户在设置用户名/密码之前不能访问该网站。然而,他们可以使用iPhone应用程序,因为该应用程序可以使用它的标识符
我知道有一个名为browser.window.move_to(0,0)的函数可以将浏览器移动到不同的位置,但OSX10.9对它来说是全新的。有什么方法可以将浏览器移动到另一个桌面吗?例如。在“桌面2”中触发命令的控制台,但我希望浏览器出现在“桌面1”中。非常感谢! 最佳答案 哈,在我尝试这个之前我正要说这可能是不可能的:browser.window.move_to(-1200,0)我的第二台显示器位于主屏幕的左侧。有效。好问题。您需要花点时间才能正确使用它,但watir似乎能够使用整个显示器Canvas。例如,如果您的显示器位于主屏