我有一个UIImageView包含在内UIScrollView.图像(通常)很大,因此用户可以将其缩小以查看整个图像.
但是,在缩小时,将其UIScrollView捕捉ImageView到滚动视图的左上角.我希望用户可以定位它,并且还没有找到"关闭它"的方法.
它有点像总是允许滚动,而不是只允许在图像放大时滚动.也许它太重要了?
有人知道吗?最初,我只是想手动创建这个功能.但UIImageViews不喜欢调整到新的大小(我已经尝试了所有的东西,无法UIImageView调整大小,除非我从中删除图片imageView,更改框架,然后重新添加).
我有一个viewcontroller和uicollectionview它在里面.
我使用了以下代码,但没有可见的图像uicollectionview,只有黄色框:
myviewcontroller.h
{
IBOutlet UICollectionView *gallery1;
//IBOutlet UIImage *inimage;
NSArray *recipePhotos;
}
@property (nonatomic, retain) IBOutlet UICollectionView *gallery1;
//@property (nonatomic, retain) IBOutlet UIImage *inimage;
Run Code Online (Sandbox Code Playgroud)
和myviewcontroller.m
- (void)viewDidLoad
{
[super viewDidLoad];
recipePhotos = [NSArray arrayWithObjects:@"im1.png","im2.png", "im3.png", "im4.png", "im5.png", "im6.png", nil];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(100, 100)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[self.gallery1 setCollectionViewLayout:flowLayout];
[self.gallery1 setAllowsSelection:YES];
self.gallery1.delegate=self;
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection: (NSInteger)section {
return recipePhotos.count;
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 1;
} …Run Code Online (Sandbox Code Playgroud) 我想把2 UIPickerViews合二为一ViewController.每个UIPickerView都有不同的数据阵列.我正在使用界面构建器来链接拾取器.我知道我将不得不使用单独的委托和dataSources,但我似乎无法正确地连接接口构建器.这是我的所有代码:
pickerTesting.h
#import <UIKit/UIKit.h>
#import "picker2DataSource.h"
@interface pickerTestingViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>{
IBOutlet UIPickerView *picker;
IBOutlet UIPickerView *picker2;
NSMutableArray *pickerViewArray;
}
@property (nonatomic, retain) IBOutlet UIPickerView *picker;
@property (nonatomic, retain) IBOutlet UIPickerView *picker2;
@property (nonatomic, retain) NSMutableArray *pickerViewArray;
@end
Run Code Online (Sandbox Code Playgroud)
pickerTesting.m
#import "pickerTestingViewController.h"
@implementation pickerTestingViewController
@synthesize picker, picker2, pickerViewArray;
- (void)viewDidLoad
{
[super viewDidLoad];
pickerViewArray = [[NSMutableArray alloc] init];
[pickerViewArray addObject:@" 100 "];
[pickerViewArray addObject:@" 200 "];
[pickerViewArray addObject:@" 400 "];
[pickerViewArray addObject:@" 600 "]; …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我必须将a的长度限制UITextField为6个字符.这工作绝对正常.一旦我结束编辑并再次开始编辑,我点击退格我的应用程序崩溃.
这是代码:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSUInteger newLength = [txtLicense.text length] + [strNumber length] - range.length;
return (newLength > 6) ? NO : YES;
}
Run Code Online (Sandbox Code Playgroud) 我有一个横向UIScrollView分页.有两个按钮.一个向左滚动scrollView到另一个向右.
左边的代码:
- (IBAction)goLeftAction:(id)sender
{
CGFloat pageWidth = _theScrollView.frame.size.width;
int page = floor((_theScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if(page>0){
page -=1;
[_theScrollView scrollRectToVisible:CGRectMake(_theScrollView.frame.size.width*page, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
scrollView当我们在第一页(页面= 0)并按下左键时,我希望按钮使显示弹跳效果.
请帮助找到实现这一目标的方法.
编辑:
如果有人需要,这是代码.
首先我加入了 goLeftAction:
[_theScrollView setPagingEnabled:NO];
[_theScrollView setScrollEnabled:NO];
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(bounceScrollView) userInfo:nil repeats:NO];
Run Code Online (Sandbox Code Playgroud)
接下来:
- (void)bounceScrollView
{
[self.theScrollView scrollRectToVisible:CGRectMake(100, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unbounceScrollView) userInfo:nil repeats:NO];
}
- (void)unbounceScrollView
{
[self.theScrollView scrollRectToVisible:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES]; …Run Code Online (Sandbox Code Playgroud) 我希望有一UIScrollView组子视图,其中每个子视图都有UITextView一个不同的文本.对于这个任务,我修改了PageControl苹果"iphone dev center"中的示例,以便将其添加UITextView到视图中,该视图用于生成滚动视图的子视图.当我运行应用程序(在模拟器和手机上)时,看不到文本,但如果我激活"用户交互"并单击它,文本会神奇地出现(以及键盘).
有没有人有解决方案或在UITextView内部取得任何进展UIScrollView?谢谢.
我能够创建一个tableviewwith textlabel和with detaillabeltext.
除此之外,是否可以添加UIButton到单元格中.
我的意思是在详细说明后,我可以放置一个UIButton(如"删除"按钮)
目前我有以下代码
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//-----------------------------------------------------------------------------------------------------
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
profileName = [appDelegate.sentItemsList objectAtIndex:indexPath.row];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSString *subjectData = [profileName.sent_subject stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
cell.textLabel.text = [NSString stringWithFormat: @"%@ ", subjectData];
cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
NSString *CompanyName …Run Code Online (Sandbox Code Playgroud) 我正在按照教程进行溢出UICollectionView.此外,我想对物品进行选择,然后是新的外观UIViewController.
我可以知道如何做到这一点?我可以UITable选择选择索引= 0,1或2等吗?代码显示正确,NSLog但没有去其他UIViewController
- (void)tapCell:(UITapGestureRecognizer *)inGestureRecognizer
{
NSIndexPath *theIndexPath = [self.collectionView indexPathForCell:(UICollectionViewCell *)inGestureRecognizer.view];
if (theIndexPath.row ==0) {
NSLog(@"****");
page *noteDetailViewControler = [[page alloc] initWithNibName:@"page" bundle:nil]; }
}
Run Code Online (Sandbox Code Playgroud)
这是完整的代码:
@implementation CDemoCollectionViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.cellCount = 10;
self.imageCache = [[NSCache alloc] init];
[self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([CCoverflowTitleView class]) bundle:NULL] forSupplementaryViewOfKind:@"title" withReuseIdentifier:@"title"];
NSMutableArray *theAssets = [NSMutableArray array];
NSURL *theURL = [[[NSBundle mainBundle] resourceURL] URLByAppendingPathComponent:@"Images"];
NSEnumerator *theEnumerator = [[NSFileManager defaultManager] enumeratorAtURL:theURL includingPropertiesForKeys:NULL options:NSDirectoryEnumerationSkipsPackageDescendants | …Run Code Online (Sandbox Code Playgroud) 我有一个UIAlertView带有2个按钮的重新加载按钮 - 确定和取消.取消按钮工作正常,但是当我想要一些动作(再次玩游戏)OK按钮不起作用,除非该动作是一个NSLog.
我的代码是m.文件:
- (IBAction)startAgainAction:(id)sender {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Warning" message:@"Have you short that want start again the game?"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"Cancel", nil];
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// My OK button
if (buttonIndex == alertView.cancelButtonIndex) {
// Action to start the game again... (don't work)
[self viewDidLoad];
} else if (buttonIndex == alertView.firstOtherButtonIndex) {
// NSLog it's accept but not other actions...
NSLog(@"Cancel");
}
}
Run Code Online (Sandbox Code Playgroud)
是的,我把UIAlertViewDelegate协议放在了h.文件
那么,为什么 …
ios ×5
iphone ×5
objective-c ×4
cocoa-touch ×2
uibutton ×2
uiscrollview ×2
backspace ×1
bounce ×1
button ×1
ios4 ×1
uialertview ×1
uiimageview ×1
uikit ×1
uipickerview ×1
uitableview ×1
uitextfield ×1
uitextview ×1
xcode ×1