我有三个视图控制器是UIScrollView的一部分.我希望能够在三者之间滑动,尽管其中一个视图控制器有一个UIPanGestureRecognizer.我使用这个平移手势识别器允许用户上下拖动手指来增加和减少矩形UIView的高度.因此,这个UIPanGestureRecognizer只需要知道向上/向下平移,滚动视图可以使用水平平移.
这方面的一个例子就像主屏幕; 你可以向左或向右滑动,但也可以向下滑动以获得聚光灯.我想要这种机制.
这是我的泛码:
- (void)pan:(UIPanGestureRecognizer *)aPan; // When pan guesture is recognised
{
CGPoint location = [aPan locationInView:self.view]; // Location of finger on screen
CGRect secondRect = CGRectMake(210.0, 45.0, 70.0, 325.0); // Rectangles of maximimum bar area
CGRect minuteRect = CGRectMake(125.0, 45.0, 70.0, 325.0);
CGRect hourRect = CGRectMake(41.0, 45.0, 70.0, 325.0);
if (CGRectContainsPoint(secondRect, location)) { // If finger is inside the 'second' rectangle
CGPoint currentPoint = [aPan locationInView:self.view];
currentPoint.y -= 80; // Make sure animation doesn't go outside the …Run Code Online (Sandbox Code Playgroud) 我有一个里面有一些选项的选择,我希望用户被发送到另一个页面,在 URI 中有一个变量,以便我可以提取它。
这是我选择的设置方式:
<select name="period" onclick="window.location.href = 'test.php?Period=' + this.selectedIndex;">
Run Code Online (Sandbox Code Playgroud)
然后我应该能够使用 $_GET['Period'] 来获取值。
但是,用户永远不会被发送到 test.php。
为什么是这样?
我正在使用Swift和Xcode 6 Beta 5,并试图在我的特定约束之间生成一个随机数.
目前我正在使用arc4random_uniform()函数,它适用于简单生成,如:
arc4random_uniform(5)
Run Code Online (Sandbox Code Playgroud)
但我试图创建一个带有复杂边界的随机数.这是我的尝试:
randomMovement = Int( arc4random_uniform( (0.25 * Int(cs)) - ( 0.175 * rd ) ) ) + Int( 0.175 * rd )
Run Code Online (Sandbox Code Playgroud)
cs和rd都是整数 - 最初,cs = 100,rd = 40.这应该生成7到25之间的随机数.但是,由于变量类型,我在Xcode中遇到了很多问题.
使用此代码,它最初显示一个错误 - 在第一个'*'上,它表示:
'Int' is not convertible to 'UInt8'
Run Code Online (Sandbox Code Playgroud)
但是当我改变它时,它会出现更多的问题,而且似乎我继续围成一圈.
出了什么问题,我该如何解决这个问题?
我正在使用此代码在用户按下按钮时显示Game Center.我希望这能在排行榜上显示出高分:
@IBAction func showScores(x : UIButton) {
var gameCenterController : GKGameCenterViewController!
if (gameCenterController != nil) {
gameCenterController.gameCenterDelegate = self
self.presentViewController(gameCenterController, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
但我在这一行上收到错误:
gameCenterController.gameCenterDelegate = self
Run Code Online (Sandbox Code Playgroud)
那读起来,
Type 'MenuViewController' does not conform to protocol `GKGameCenterControllerDelegate`
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
如何将GameCenter实施到我的游戏中,以便将用户的高分添加到排行榜中,按下按钮可以查看它们?
我正在向PageViewController添加三个视图控制器,如下所示:
[pvc setViewControllers:[NSArray arrayWithObjects:svc, bvc, tvc, nil] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) {
Run Code Online (Sandbox Code Playgroud)
}];
但是,应用程序会抛出异常并在此行停止.当我检查日志导航器时,它只是说'(lldb)'.出了什么问题?
编辑:好的,谢谢保罗.我对Objective-c很新; 如何实现这些方法来获取我的三个视图控制器之间的滑动?
这是appDelegate.m中的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.;
UIPageViewController *pvc = [[UIPageViewController alloc] init]; // Create new PageViewController
BarsViewController *bvc = [[BarsViewController alloc] init]; // Create BarsViewController
StopwatchViewController *svc = [[StopwatchViewController alloc] init]; // Create StopwatchViewController
TimerViewController *tvc = [[TimerViewController alloc] init]; // Create TimerViewController
[pvc setViewControllers:[NSArray arrayWithObjects:svc, bvc, tvc, …Run Code Online (Sandbox Code Playgroud) 我想在我的AppDelegate.m中NSNotification从这个方法发送一个(当UIButton点击时):
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0){
//cancel clicked ...do your action
// HERE
}
}
Run Code Online (Sandbox Code Playgroud)
..并在我的一个接收它UIViewControllers.我怎样才能做到这一点?
编辑更多信息:我正在制作一个警报应用程序,当用户按下时UIButton,我想停止警报.我想这NSNotifications是从AppDelegate.m文件获取信息到ViewController.m文件的唯一方法?
我正在手机上使用Xcode 5和iOS 7制作iPhone应用程序; 该应用程序适用于iOS 7.但是,当我在iPhone 6.1模拟器上运行该应用程序时,我收到此消息:
2013-09-01 10:46:30.075 Bars[30745:c07] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't
want. Try this: (1) look at each constraint and try to figure out which you don't
expect; (2) find the code that added the unwanted constraint or constraints and
fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you
don't understand, refer to the documentation for the UIView
property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x81b80a0 …Run Code Online (Sandbox Code Playgroud) 我正在制作计时器应用程序.用户设置时间,应用程序从那里倒计时.我添加了一个UILocalNotification,因此即使你不在应用程序中它也会弹出,告诉你计时器已经完成:
在我的视图控制器中:
- (void)setupLocalNotifications {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
totalSeconds = (setHour * 60 * 60) + (setMinute * 60) + (setSecond);
NSDate *now = [NSDate date];
NSDate *dateToFire = [now dateByAddingTimeInterval:totalSeconds];
localNotification.fireDate = dateToFire;
localNotification.alertBody = @"Timer Done";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = 1; // increment
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil];
localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
Run Code Online (Sandbox Code Playgroud)
在我的APPDELEGATE:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window …Run Code Online (Sandbox Code Playgroud) 我有一个UIScrollView,我有三个视图,用户可以在其间滑动.我想在中间页面打开应用程序.我怎样才能做到这一点?
ios ×7
objective-c ×4
swift ×2
uiscrollview ×2
xcode ×2
arc4random ×1
autolayout ×1
delegates ×1
game-center ×1
iphone ×1
javascript ×1
php ×1
random ×1
swipe ×1